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

163
Vistas
I got a problem with lef hand Invalid left-hand side in assignment

Code

I'm trying to write a program to count the average of 5 numbers that are entered into input fields, but it's not working as expected, what's wrong with my code?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

document.getElementById returns element object which has multiple properties.

If you want to get value of input field, after selected input field you can access it's value using value property, e.g.

var num1 = document.getElementById('n1').value;
//                                      ^^^^^^

Now your num1 variable contains the text entered into input field. Notice that I said text, not number. If you want to apply math to the values, you need to convert them to numbers, like this:

var num1 = Number(document.getElementById('n1').value);
//         ^^^^^^^                                   ^

Only then you will get correct result. But we're not done yet, as you probably want to see that result. As I mentioned previously, document.getElementById gives you reference to the element, that has multiple properties. Another property is innerText. You can set it to the value you want to be able to see it:

document.getElementById('everresult').innerText = result;
about 4 years ago · Santiago Gelvez 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