Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda