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

135
Vistas
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 Respuestas
Responde la pregunta

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 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