-3

I'm just starting JavaScript and I can't declare a variable. Possible that it is being declared but when I use the variables in a math equation there is no output from that equation.

For example:

let x = 5; <br>

let y = 6; <br>

let z = x + y; <br>

document.getElementById("demoVariables").innerHTML = "The value of z is " + z;

<br>

//demoVariables is a paragraph block level element which is supposed to change to "The value of z is " and the value of z after that but for now is not being used or altered and I don't know why.
<h1>JavaScript Variables</h1>

<p>In this example, x, y, and z are variables.</p>

<p id="demoVariables"></p>
<br>
<br>

I load this .html file into the web browser and the only thing that is output to the web browser is this:

<h1>JavaScript Variables</h1>

<p>In this example, x, y, and z are variables.</p>
New contributor
selectstart is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
9
  • 2
    Please format this as code block. Also, why are there <br>s in your script? Commented 5 hours ago
  • 3
    You can't use HTML like <br> in <script> blocks. Aren't you getting syntax errors? Commented 5 hours ago
  • I edited your post to fix the syntax errors Commented 5 hours ago
  • @Barmar maybe you can tell me if this is a valid edit or should not be fixed? Commented 5 hours ago
  • 3
    @Brentspine Since it's almost certainly the cause of their problem, you shouldn't edit out the syntax errors. I kept them when I converted to Stack Snippet. Commented 5 hours ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.