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

177
Views
Why is my code calculating the percentage incorrectly?

I am a beginner in JavaScript. I wrote this function to calculate the percentage of three values, but the output is showing incorrectly. It is showing 176.33 instead of 74.3

function percentageCalculator(history, math, science) {
  let percentage = history + math + science * 100 / 300;
  console.log(percentage);
};

percentageCalculator(88, 65, 70);

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

0

It should be:

let percentage = (history + math + science) * 100 / 300;

Like math, JavaScript also have calculation order.

about 4 years ago · Juan Pablo Isaza Report

0

After adding the appropriate surrounding brackets. You could just divide by 3 directly instead of multiplying by 100 and then dividing by 300:

function percentageCalculator(history, math, science) {
  const percentage = (history + math + science) / 3;
  return percentage;
}

console.log(percentageCalculator(88, 65, 70).toFixed(1));

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!