Review
Last day we saw how we can add a JavaScript
program to a web page: we use the HTML element <script>
, with its companion closing tag </script>
. Inside those two tags we write our program!
Our first program consisted in printing some text on the body of the page when using the htmlLiveEditor. The first message we printed was Hello World!.
But, in order to build a web app like Facebook, Google Maps or Gmail, we need more than just printing a string of characters. Indeed, a computer program consists in much more than simply printing something on the screen!
Today
Today we have seen one new key concept: a variable. In computer science, a variable consists of two things, a label and a value... Well, I'm lying a bit. Actually, it consists of three things, a label, a value and a memory location.
The label myName
is actually just an address. It points to the memory address of the start of the data we store there ('J').
Code:
Defining a variable:
var myName = "John" ;
Computer Memory
We have also seen how to print things on a dialog window using alert
.
Homework
Below you have the JavaScript code we have worked with today. Make sure to copy&paste it in your HTML live editor inside the content of the <script>
tag. Do the homework stated at the end of this code sample. When you are done, print the code in a PDF file and send it to me as an attachment. Note: Make sure the PDF file shows all the code in your page!