the code works with let but not with const. if I use a constant the code will not work at all but I use variable or let then the code works.
let x, y, z;
x = 10;
y = 20;
z = x + y;
document.querySelector("#statement").innerHTML =
"When you add the var x and y the value of z is " + z + ".";
Consts need to be initialized, so const x, y, z won't work.
The const variables need to be initialized. So, your code would be:
const x = 10;
const y = 20
const z = x + y; // or just seriously assign 30 to it
document.querySelector("#statement").innerHTML =
"When you add the var x and y the value of z is " + z + ".";
Also keep in mind that const variables cannot be reassigned.
If you want the variables' values to change, use var or let :
var x, y, z;
x = 10;
y = 20;
z = x + y;
document.querySelector("#statement").innerHTML =
"When you add the var x and y the value of z is " + z + ".";
Consts need to be initialized
const x = 10 //work
const y //error
y = 20
and const is immutable
const x = 10
x = 10 // error