9.1.7 Checkerboard V2 Codehs

You hardcoded or multiplied the lists without using explicit assignments.

In many Karel-based versions of this task, the difficulty lies in the "turnaround." Once Karel reaches the end of a row, the program must determine if there is another row above it. If so, Karel must turn, move up, and position itself to face the opposite direction to begin the next line. This requires careful use of

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

Using setFilled(true) alone might leave a tiny border. Some CodeHS exercises expect setFilled(true) without setColor for the outline. If gaps appear, set the outline color to match the fill color: 9.1.7 Checkerboard V2 Codehs

If you’re working through the CodeHS Java (or JavaScript) Graphics track, you’ve probably reached . This is a classic “level-up” from the basic checkerboard challenge. It’s designed to test your understanding of nested loops, conditional logic, and coordinate math.

In , you might have created a static 8x8 board. In Checkerboard V2 , the requirements typically change in one of two ways (depending on your school’s version):

In the v2 exercise, your task is to programmatically create an 8x8 grid that visually alternates between two values (0 and 1) to resemble a checkerboard pattern, given a provided print_board(board) function that displays the grid. You must construct a list of lists (a 2D array) where the pattern alternates every row and column, using a Python loop to construct each row and then appending it to your grid. You hardcoded or multiplied the lists without using

def print_board(board): for row in range(len(board)): print(" ".join([str(cell) for cell in board[row]]))

for (var row = 0; row < NUM_ROWS; row++) for (var col = 0; col < NUM_COLS; col++) // Logic for coloring goes here Use code with caution. Copied to clipboard 3. Apply the parity logic

First, create a variable to hold your grid. You will start with an empty list and then append rows to it. In CodeHS, you are typically expected to build an structure. 2. Create the Nested Loops You need two loops: one for the rows and one for the columns. outer loop iterates through the row indices ( inner loop iterates through the column indices ( 3. Apply the Alternating Pattern Inside the nested loop, check the sum of the current . Use the modulus operator to check for even or odd values. if (row + col) % 2 == 0 If true, set the cell to If false, set the cell to 4. Print the Result This requires careful use of for (var row

Before jumping to the code, review these topics:

To create the Checkerboard V2 pattern, students must employ a systematic and algorithmic approach. The solution involves using nested loops to iterate over the grid, making decisions about the color of each square based on its position. A common strategy involves using the sum of the row and column indices to determine whether a square should be black or white.

var x = col * SQUARE_SIZE; var y = row * SQUARE_SIZE; var square = new Rectangle(SQUARE_SIZE, SQUARE_SIZE); square.setPosition(x, y); // The "Checkerboard" Logic if ((row + col) % 2 == 0) square.setColor(COLOR_ONE); else square.setColor(COLOR_TWO); add(square); Use code with caution. Common Pitfalls to Avoid

: Users often try to build a "1,0,1,0" list and a "0,1,0,1" list and append them alternately. While this works for the visual output, it may bypass the lesson's goal of teaching index-based assignment. Indentation Errors

Mastering CodeHS 9.1.7: Checkerboard V2 The assignment is a fundamental milestone in beginner computer science curriculum. It tests your mastery over two-dimensional (2D) lists and nested loops in Python.