This JavaScript page answers introductory tutorial exercises 1 to 4

Notes

Exercise 1 could have used inline code rather than a function. But it couldn't use an event handler (say invoked onLoad) containing document.write() to write into the current document. It could however be re-written event driven and use the innerHTML property of the level 1 header.

Exercise 2 could also use inline code.


Exercise 3

+

Exercise 4

It's because where + has one or two string operands it will concatennate rather than add whereas - will always subtract if the actual values are numeric.

21 event handlers I think. onError is the one that triggers when an error occurs loading a page or image

for .. in iterates over all the properties of an object e.g. the results of

for (var i in navigator)
    document.write("navigator." + i + " = "+ navigator[i] + "<br >");

are: