Where are these instructions?
1 – between beginning and ending script tags:
2 – on the right hand side of the equal sign in some HTML tag attribute clauses:
alert ("Hello world.");
Type the HTML page above into a brand new document called hello.html. Open it with your browser and observe what happens.
Make a second copy of hello.html, call it hello2.html. Add another alert line with your name between the quote marks instead of Hello world. Open hello2.html with your browser and observe what happens. Congratulations. You are programming!
A note about the exercise:
If you have difficulty and get an error, carefully check that each symbol has been copied correctly from the text.
Question: How is this web page different from your usual web browsing experience?
Interacting with the viewer of the web page
Creating dynamic (moving) content, changing the web page
Creating different content based on different situations
Calculating with numbers, manipulating text and images
Exercise 1 gave a simple example of output from a program and forced you to click a button (input) to carry on. In this example there is no input required from the user. The program just makes the browser display a normal looking web page.
document.write("Goodbye alert boxHello world."); document.write("Again, we say goodbye!");
Type the above web page into a file helloworld2.html and view it with your browser.
Question: What do you notice about the spacing?
Question: To make Again, we say goodbye! appear on a different line, what would you have to do?
A note about this exercise:
Create a new web page with a verse from your favourite poem, rhyme, limerick... using document.write and to make line breaks. If you have more than one verse, you can use to start each new verse.
A variable is a named place in the memory of the computer. A variable stores information. Some of the types of information that can be stored are:
To introduce a variable use the keyword var followed by the name of the variable. Optionally, give the variable a starting value.