Codehs Extra Quality | 9.1.7 Checkerboard V2

Next, we need to determine the color of each square. We can do this by using a conditional statement that checks the row and column numbers. If the sum of the row and column numbers is even, we'll draw a black square. Otherwise, we'll draw a white square.

If you're working through the CodeHS Java course (or similar), you've likely encountered the exercise. It builds on the basic checkerboard concept but adds constraints that force you to think carefully about loops, conditionals, and drawing order.

def build_fancy_checkerboard(rows, cols, char_a='X', char_b='O'): board = [] for i in range(rows): row = [] for j in range(cols): if (i + j) % 2 == 0: row.append(char_a) else: row.append(char_b) board.append(row) return board 9.1.7 Checkerboard V2 Codehs

This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later.

If you find the post-row toggle confusing, you can reset isBlack each row explicitly based on row parity: Next, we need to determine the color of each square

Another efficient way to solve this is to fill the rows directly by alternating [1, 0, 1, 0, 1, 0, 1, 0] and [0, 1, 0, 1, 0, 1, 0, 1] .

When you run the code, you should see a perfect 8x8 checkerboard with alternating colors, no bleeding, no misalignment, and the first square of row 0 black, row 1 red/white, row 2 black, etc. Otherwise, we'll draw a white square

To ensure your solution is correct, you can test it with these example inputs:

for (var row = 0; row < 8; row++) for (var col = 0; col < 8; col++) // code to draw a square will go here

If the row index is even, the pattern might start with Color A.