Lesson Three: Assigning Values to Variables
- A variable is used to reserve a storage space inside the memory of the computer. It is like a drawer in a cabinet. The drawer being the memory space and the cabinet being the computer's memory.
- Create a variable in your JavaScript file by putting this code above the document.write("488 Million Years Ago the Mollusks Appeared"); code:
var event1;
- The var event1; code establishes a space in memory with the label of event1.
- Enter this code to insert text into the event1 variable memory space:
event1 = "488 Million Years Ago the Mollusks Appeared";
- Now when you refer to the variable event1, the browser will use the text that is stored in memory ("488 Million Years Ago the Mollusks Appeared".)
- Substitute the event1 variable for the text that is currently in the document.write() parenthesis.
- Your JavaScript code should now look like this:
var event1;
event1 = "488 Million Years Ago the Mollusks Appeared";
document.write(event1);
- Save the JavaScript file and test your program. You should get the same result that you got in lesson two only this time you achieved the results using a variable:
Lesson Four: More Variables