Assignment

To make sure you understand everything in this chapter, try this assignment.

Write a script that creates bar charts. This script should first ask a visitor how many bars to include in the chart. If the visitor wants four bars, the script should then ask for four numbers, ranging from 1 to 10, and draw a bar for each. Figure 8-20 through Figure 8-22 demonstrate what I mean. To draw the bars, create a square GIF, or use square.gif, which is available at http://www.bookofjavascript.com/Chapter08/square.gif. If someone wants a bar that's ten squares high, use a loop to write

window.document.writeln("<img src='square.gif'>")

ten times to the page. This is another tough assignment, so give yourself plenty of time to do it.

Figure 8-20. Asking ...

Get The Book of JavaScript, 2nd Edition 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.