Write a program that draws a checkerboard pattern. Your program should create a canvas of 400x400 pixels. The checkerboard should have 8 rows and 8 columns of squares. Each square should be 50x50 pixels. Alternate the colors between black and gray (or red and black, depending on the version). The top-left square should be gray.
function start() var row = 1; while (true) // Determine if row starts with beeper var startWithBeeper = (row % 2 == 1); // Fill the row var col = 1; while (true) if (startWithBeeper) if (col % 2 == 1) putBeeper(); 9.1.6 checkerboard v1 codehs
: Inside the loops, use an if-else statement or a simple calculation to assign the value based on the parity of the sum of the indices. Write a program that draws a checkerboard pattern
The canvas is 400×400, but squares don't align perfectly. Fix: Calculate the window size dynamically from the square size and number of squares, as shown in the constants above. Each square should be 50x50 pixels
Here is the Java code for CodeHS 9.1.6 Checkerboard v1 :