Update 07/18/14 |
|
Declaring and using variablesIn JavaScript declaring variables is similar to other declaration techniques in other common programming languages var nameOfVariable Where "nameOfVariable" is the name of the new variable being declared. Once the variable has been declared you can use it later in the script. Here is a simple example of the declaration and use of variables. var favoriteColor ="blue"; if(favoriteColor="blue") document.write("My favorite color is blue"); else document.write("My favorite color is not blue"); </script> Click here to execute my favorite color script. In this example the favoriteColor variable is given a value of "blue", making the if part of the statement true and executing the document.write() method under the if part of the statement.Try modifying my code and assign a different value to the favoriteColor variable The if part of the statement would then be false and the code under the else part of the statement would execute. In this case it is a document.write method() and you should see My favorite color is not blue after changing the value of the favoriteColor value.
|
This site was last updated 07/08/14