9.1.6 Checkerboard V1 Codehs (1000+ SECURE)

Some versions of the CodeHS exercise use red instead of gray. If your prompt says "red and black", simply change the color in the conditional:

: Dividing the canvas width by NUM_COLS (8) ensures the grid perfectly stretches from the left edge to the right edge. 9.1.6 checkerboard v1 codehs

// Create the Grid to display the board Grid grid = new Grid(size, size, 50); Some versions of the CodeHS exercise use red instead of gray

To solve this efficiently, we cannot simply write code for one row and copy-paste it. We need a general algorithm that handles the pattern. Core Components of the Solution We need a general algorithm that handles the pattern

if ((row + col) % 2 == 0) square.setFillColor(Color.RED); else square.setFillColor(Color.BLACK);

: We start by creating an empty list called board , which will become our 8x8 grid.

function printBoard(board) for (let i = 0; i < board.length; i++) console.log(board[i].join(" "));


Comments are closed