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

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

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 Report

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