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 to find the area of circle in javascript by the given radius

**Write a function area that calculates the area of a circle. The function is given the radius of the circle. **

my code is this

let r;
    let radius=r*r;
    function area(r){
    return (Math.PI.radius);
    }

    

Error is showing that "area(0) does not return 0, but undefined." please explain this code.

I am new to this world please don't mind if you think this is one of the simple questions I have no one to ask except you guys!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Math.PI does not have a radius - it is a mathematical constant, which you have to multiply with the squared radius of the circle. Also you did not assign any value to r - so it is undefined. This one works:

function area(r) {
  return Math.PI * r ** 2; /* r ** 2 is the JS notation of potenatiating a number */
}

console.log(area(0));
console.log(area(1));
console.log(area(5));
console.log(area(10));

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!