Learn Create Your Own Split Screen

Next Page

We'll move our RandInt function up to our preface area, just to tidy things up.

We'll also generate our random circles inside a for loop to make 100 random circles.

And finally, we'll add some code into fillCircle to pick a random colour. The way we'll do this is generate a random number which will be 0, 1 or 2. In a series of if-then-elses we'll set a different fillStyle depending on the result.

We'll also call our fillCircle function something slightly different -- CircleRandColour, to be more descriptive of its new functionality.


Try changing the number of circles to 10. Try 1000!

Try changing the maximum circle size from 30 to something else.

Challenge: try changing the code to include a fourth random colour in the repertoire.