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

169
Views
¿Por qué mi código calcula el porcentaje incorrectamente?

Soy un principiante en JavaScript. Escribí esta función para calcular el porcentaje de tres valores, pero la salida se muestra incorrectamente. Está mostrando 176.33 en lugar de 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

Debería ser:

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

Al igual que las matemáticas, JavaScript también tiene un orden de cálculo.

about 4 years ago · Juan Pablo Isaza Report

0

Después de agregar los corchetes circundantes apropiados. Podrías simplemente dividir por 3 directamente en lugar de multiplicar por 100 y luego dividir por 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!