9.1.6 Checkerboard V1 Codehs [updated] 99%
You need to create a checkerboard pattern (alternating black and red squares) using a grid of squares, typically with n rows and n columns (often n = 8 for a standard checkerboard).
To achieve this, the program must evaluate the position of each cell based on its row and column indices. Key Programming Concepts Used 9.1.6 checkerboard v1 codehs
In the CodeHS exercise , the goal is to create a 2D array representing an You need to create a checkerboard pattern (alternating
function start() // Define the size of the board var NUM_ROWS = 8; var NUM_COLS = 8; // Outer loop handles the rows for (var row = 0; row < NUM_ROWS; row++) // Inner loop handles the columns for (var col = 0; col < NUM_COLS; col++) // Check if the sum of row and col is even if ((row + col) % 2 == 0) drawSquare(row, col, Color.red); else drawSquare(row, col, Color.black); function drawSquare(row, col, color) var sideLength = getWidth() / 8; var x = col * sideLength; var y = row * sideLength; var rect = new Rectangle(sideLength, sideLength); rect.setPosition(x, y); rect.setColor(color); add(rect); Use code with caution. Key Components Explained 1. Nested Loops var NUM_COLS = 8
: Create an empty list called board and fill it with eight rows of eight zeros.