Lets declare and use a few variables, the structure is always the same for declaring variables in JavaScript: var <<variable name>>; will declare a variable.
you store something in a variable using the = sign for example:aVariable = 3;
and you get the contents of a variable by simply giving its name: aVariable
putting this all together and the lines:var aVariable = 3;
var anotherVariable = aVariable + 1; will result in two new variables being created aVariable that contains the value 3 and anotherVariable that contains the number 4, note I slipped in some simple arithmetic here but its no biggy :)
just stick this code into the test.html file where it says //PLACE CODE HERE, et voila!
function start() {
var aVariable = 11;
var newVariable = 32;
var whatAmI = aVariable + newVariable;
}
What is the value of the variable whatAmI?
Ok, so I'll be the first to admit thats a boring program try this to see if you were right
function start() {
var aVariable = 11;
var newVariable = 32;
var whatAmI = aVariable + newVariable;
document.write( "the value is " + whatAmI );
}
What do you think the result to this one will be?
function start() {
var aVariable = 11;
var newVariable = 32;
aVariable = aVariable + 1;
var whatAmI = aVariable + newVariable;
document.write( "the value is " + whatAmI );
}