How it shows the value of a var within a java html span

Asked

Viewed 18 times

-2

Staff searched the forum nothing else worked would you like to know how it shows the value of a var within span? I’m trying to

Var exemplo = 10;

Document.getElementById(pontos).innerHTML = Exemplo;

<span id="exemplo"></spam>

But it’s not working If anyone can explain me in a simple way I’m beginning to speak the language

  • document.getElementById("pontos").innerHTML = exemplo; javascript is case sensitive, beware of uppercase

1 answer

0

Hello,

Let’s start with the mistakes:

Javascript is a language case sensitive, that is, the reserved word var will not be interpreted as Var. The same occurs with the Document that should be document and Exemplo that should be exemplo, since you declared him with the D minuscule.

All Javascript code within an HTML code must be within the tag <script></script>.

Knowing this, convert your code to this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <span id="exemplo"></span>

    <script>
      var exemplo = 10;

      document.getElementById('exemplo').innerHTML = exemplo;
    </script>
  </body>
</html>

Browser other questions tagged

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