Graphic JavaScript


Back to index
License Plate Factory

Your browser does not support the HTML5 canvas tag.

ASSIGNMENT:

There are two interesting things you should look for in the sample code:

1) can.addEventListener('click',newOne, false);
This line tells the canvas area to do something when a mouse is clicked within its boundaries. It calls a function called newOne in this case.

2) c = Math.floor(Math.random()*26);
Math.floor and Math.random work together to produce a random integer between 0 and 25. Math.random produces a floating point value greater than zero and less than one. Math.floor chops up any values to the right of the decimal point to produce a whole number.

The rest of the applet should be quite intelligible at this point.

Your assignment is to create a canvas area containing a 3x3 array of license plates which all update each time the canvas area is clicked. Additionally, make the letters and numbers of the plate display in a color selected randomly from a pool of at least six colors.