To visit every "cell" in the checkerboard, use a nested for loop. The outer loop handles the rows, while the inner loop handles the columns. javascript
function start() for (var row = 0; row < NUM_ROWS; row++) for (var col = 0; col < NUM_COLS; col++) // Calculate coordinates var xPos = col * SQUARE_SIZE; var yPos = row * SQUARE_SIZE; // Determine alternating color if ((row + col) % 2 === 0) drawSquare(xPos, yPos, Color.RED); else drawSquare(xPos, yPos, Color.BLACK); Use code with caution. Common Mistakes and How to Avoid Them
To visit every "cell" in the checkerboard, use a nested for loop. The outer loop handles the rows, while the inner loop handles the columns. javascript
function start() for (var row = 0; row < NUM_ROWS; row++) for (var col = 0; col < NUM_COLS; col++) // Calculate coordinates var xPos = col * SQUARE_SIZE; var yPos = row * SQUARE_SIZE; // Determine alternating color if ((row + col) % 2 === 0) drawSquare(xPos, yPos, Color.RED); else drawSquare(xPos, yPos, Color.BLACK); Use code with caution. Common Mistakes and How to Avoid Them