Code gives Document.getElementById error is not a Function

Asked

Viewed 852 times

1

    Uncaught TypeError: document.getELementById is not a function
    at inserindoValores (desafio-array.html:17)
    at HTMLButtonElement.onclick (desafio-array.html:48)
inserindoValores @ desafio-array.html:17
onclick @ desafio-array.html:48

What’s up, pessu? Could someone help me visualize what’s wrong with my code? This message keeps popping up when I try to impute a new value.

The code is this:

<script>

      var objetos = ['Cadeira', 'Impressora', 'Garfo'];



      function inserindoValores(valor){

      var novoObjeto = document.getELementById('resultado').value;

        if (valor === 'adiciona') {

            if(novoObjeto === ''){
              alert('Informe um valor válido')
            } else{
              if (objetos.indexOf(novoObjeto)) {
              alert('Objeto já foi adicionado');
              } else {
                objetos.push(novoObjeto);
                console.log(objetos);
                document.getELementById('resultado').value = '';
              }
            }

        } else if (valor === 'ordena'){
          objetos.sort();
          console.log(objetos);
        }

      };


    </script>

    </head>

  <body style="padding: 50px 50px">

    <input type="text" name="desafio" placeholder="Digite um objeto:" id="resultado">
    <button type="submit" onclick="inserindoValores('adiciona')">Adicionar</button>
    <button type="submit" onclick="inserindoValores('ordena')">Ordenar</button>


  </body>   

</html>

Thanks so much! I’m starting to learn JS and taking 7x0 so far hsauhsauh

  • 2

    Mari, javascript is case sensitive and you wrote getELementById , you realize the L is uppercase, leave it in lowercase: getElementById

1 answer

1

Javascript is a language case sensitive, This means that it differentiates between upper and lower case characters. In your code you wrote getELementById with uppercase L, when the correct is lowercase. Try the following code:

document.getElementById('resultado').value
  • Wow, guys! Reaal, I didn’t even realize I had uppercase L.. Very obligatedaa!

  • Vixe, but it still doesn’t work. Gives this error:challenge-array.html:24 Uncaught Referenceerror: Invalid left-hand side in assignment at inserindoValues (challenge-array.html:24) at Htmlbuttonelement.onclick (challenge-array.html:48)

  • I could not simulate this new error, maybe you have some difference in your current code and posted in the question, see this link to learn more about this error, if it doesn’t help, it might be interesting to create a new question for it with all its current code.

  • I just redo, I had inserted an element, but I removed and this error stopped happening, but now regardless of what I write it always leads to 'Object has already been added'.

  • This happens because of the line if (objetos.indexOf(novoObjeto)), the correct way to compare the result of a indexOf this is how if (objetos.indexOf(novoObjeto) >= 0)

  • SIMMM managed to reach this conclusion just now and FUNCIONOUUU, feliz dmais ahahha brigada, Uricio!!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.