x = 10;
y = 5;
z = x + y;
document.getElementById("tutorial").innerHTML = z;
The value stored in the element with id tutorial will be replaced by the value assigned to z, which is 15, and updated dynamically.
A good technique to adhere to is to put white space around operators, such as =, +, -, *, and /. The technique will help you read the code easier. The white space will allow the user to understand what is going on, and will also give you room to think. The code may take up more room, but lengthy code is not always a bad thing. I would rather have 10 short lines of code that can be read easily, instead of 5 longer and more condensed lines of code.
For the best readability, the programmer should avoid lines of code that are longer than 80 characters in length. The longer the code is, the harder the code will be to read overall. The line of code should really not be any longer than the typical length of a line spanning your screen. If you do have to cut a line, the best way to do so is at the operator:
document.getElementById("tutorial1").innerHTML = "Hello World, ";
document.getElementById("tutorial2").innerHTML = "how are you today? ";
Functions will return later on in this tutorial, but for now let us finish the statements page up with more specific keywords.
break will terminate a switch or a loop
continue will jump out of a loop and start back at the top
debugger stops execution of JS code, and will call the debugger if possible
do .. while will repeat a block of code while the conditional statement returns true
for is reserved for specific for loops
return exits a function
switch will execute a block of code depending on the conditions present
var is a reserved word that will declare a variable
Just follow the buttons to continue the tutorial, Guest