Learn Create Your Own Split Screen

Next Page

One point on good coding style:

Recall that in our preface section of the code, we declare our canvas:

<canvas id=myCanvas width=300 height=300 style="background-color: pink">

Then, when we're generating circles in random locations on the canvas, we do this:

fillCircle(RandInt(300), RandInt(300), RandInt(30));

The use of "300" in the fillCircle obviously corresponds to the "300" when the canvas is created. Makes perfect sense.

But what if weeks later we chose to make the canvas a different size - say 400 x 500. We'd need to make the change in two different places.

For this reason, it's much better style to do something like this:

fillCircle(RandInt(myCanvas.width), RandInt(myCanvas.height), RandInt(30));

Remember, "myCanvas" is just a name I made up at the very beginning, but I need to be consistent in using it, otherwise it would be like if your teacher suddenly started calling your classmates by completely different names each day.