Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

547
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda