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

96
Vistas
Problem with math operations in javascript

I have a question regarding the code:

<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>

<script>
var a = 3;
var x = 275.15 * a;
var z = 298.15 * a;
document.getElementById("demo").innerHTML = x, z;
</script>

</body>
</html>

I want to return both x and z, but it seems like this code only returns x. What am I doing wrong? :)

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You're using the comma operator here: .innerHTML = x, z;. The comma operator works like this: It evaluates its left-hand operand, throws away the result, then evaluates its right-hand operand and takes that value as its result. So what you have there is equivalent to .innerHTML = z (since x has no side effects). If you want to show both, use string concatenation (.innerHTML = String(x) + ", " + z;), or a template literal (.innerHTML = `${x}, ${z}`;), or similar.

about 4 years ago · Juan Pablo Isaza Denunciar

0

<p id="demo"></p>

<script>
  var a = 3;
  var x = 2 * a;
  var z = 9 * a;
  document.getElementById("demo").innerHTML = (x +","+ z);
</script>

it's not a problem with math operators,hope this will help u

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