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

175
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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