Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
How do i get my simple point to line calculator to work (in javascript)

im experienced in python but not javascript the # represent the numbers i would put in

let r
let m2
let b2
let x2
let y2
function rcirc(x,y,m,b) {
  m2 = -1/m
  b2 = y - (m * x)
  y2 = (b2 - b) / (m - m2)
  x2 = (y2 - b) / m
  return(x,y)
};

rcirc("#","#","#","#");
console.log(x,",",y);
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You should not have those global variables -- that wouldn't even work in Python. Define them in the function as local variables.

A difference with Python is that there is no concept of tuple in JavaScript, so you would return the values as an array (i.e. a list in Python). But of course, you should return the result of the calculation, not the input values!

Here is how it could look:

function rcirc(x, y, m, b) {
  let m2 = -1/m;
  let b2 = y - (m * x);
  let y2 = (b2 - b) / (m - m2);
  let x2 = (y2 - b) / m;
  return [x2, y2];
}

let point = rcirc(1, 2, 3, 4);
console.log(point);

about 4 years ago · Juan Pablo Isaza Denunciar

0

While returning the pair in the function, [ ] must be used instead of ( ). Also, the new/calculated value [x2,y2] must be returned.

Also, the returned value must be stored in a variable or pair as per your wish.

let r
let m2
let b2
let x2
let y2
function rcirc(x,y,m,b) {
  m2 = -1/m
  b2 = y - (m * x)
  y2 = (b2 - b) / (m - m2)
  x2 = (y2 - b) / m
  return [x2,y2]
};

let [x,y] = rcirc(1,2,3,4);
console.log(x,y);

Hope this helps!

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda