Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!