Trying Programs

When you want to run the code shown in this book and play with it, one possibility is to go to http://eloquentjavascript.net/ and use the tools provided there.

Another approach is to simply create an HTML file containing the program and load it in your browser. For example, you could create a file called test.html with the following content:

<html><body><script type="text/javascript">

var total = 0, count = 1;
while (count <= 10) {
  total += count;
  count += 1;
}
document.write(total);

</script></body></html>

Later chapters will tell you a little more about HTML and the way a browser interprets it. Note that the operation print in the example has been replaced with document.write. We will see how to create the print function in Chapter 10 ...

Get Eloquent JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.