The final change to the HTML file is to tell the browser how to start running the program in our Javascript file. This must not happen until all files have been loaded into the browser from the server. A simple way to do this is to add an attribute to the starting tag of the body element:
<body onload="run()">
This means that when everything is loaded we want to start with a function called run. The brackets, run()
, show that we mean to use a function. After the next exercise we must explain what a function is but first see some of this in action.
Once again there are other ways to do this but for now we will stick to the simplest way.
It is important to realise that Javascript is case-sensitive. You could have two functions called run()
(all lower-case) and Run()
(capital R). They would be two quite independent things. This would be a very unwise thing to do though. When errors occur (and they WILL) it would make diagnosing the cause more difficult. Keep things as simple and clear as you can. There is more about naming things on a later page.