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

545
Vistas
Calculation of a sphere in JavaScript

I'm trying to calculate the volume of a sphere, with floating points, but I couldn't quite understand the logic behind the exercise.

Write a program that calculates and displays the volume of a sphere, providing the value of its radius (R). The formula for calculating volume is: (4/3) * pi * R3. Consider (assign) to pi the value 3.14159.

const PI = 3.14159;

let R = parseFloat(gets());


//TODO: Fill in the blanks with a possible solution to the challenge

print("VOLUME =          "  +          );
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You should try by yourself, but here is the solution and explanation.

If you are using javascript on the browser:

let radius = parseFloat(prompt("Enter value for radius: "));
let volume = 4/3 * Math.PI * Math.pow(radius, 3);
console.log("The volume is: ", volume);

We are requesting the user input with prompt() and assigning it to radius variable. We calculate the volume with the equation v = 4/3 πr³, Math.PI represents the number PI and Math.pow() calculates the given base (this case, radius) taken to the power of the given exponent. Last step is to print the result to the output, which is done with console.log()

about 4 years ago · Juan Pablo Isaza Denunciar

0

Reading a lot of the tips here, I solved it, I don't know if it's the best way, but I solved it.

const PI = 3.14159;

let R = parseFloat(gets());
var raio = parseFloat(R);

var volumeEsfera = (4/3) * PI * Math.pow(raio, 3);


print("VOLUME =          "  +    volumeEsfera.toFixed(3) );
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