9.1.6 Checkerboard V1 Codehs May 2026
for i in range(8): row = [] for j in range(8): # Check if the sum of row and column indices is even if (i + j) % 2 == 0: row.append("red") else: row.append("black") board.append(row)
In this specific CodeHS exercise, you typically edit the file named Checkerboard.java. You are expected to fill in the logic inside the nested for loops to set the color of the Rectangle objects stored in a 2D array. 9.1.6 checkerboard v1 codehs
Here is the completed code for the relevant section: for i in range(8): row = [] for
/* * This class represents a checkerboard. * It creates a grid of Rectangle objects. */ public class Checkerboard private Rectangle[][] board; private int size;public Checkerboard(int size) this.size = size; board = new Rectangle[size][size]; // Create the Grid to display the board Grid grid = new Grid(size, size, 50); // Nested loops to iterate through the 2D array for(int row = 0; row < size; row++) for(int col = 0; col < size; col++) // 1. Create a new Rectangle object Rectangle rect = new Rectangle(); // 2. Determine color based on row + col sum if((row + col) % 2 == 0) rect.setColor(Color.BLACK); else rect.setColor(Color.WHITE); // 3. Add the rectangle to the array board[row][col] = rect; // 4. Add the rectangle to the Grid to visualize it grid.add(rect, row, col);
Course: CodeHS Introduction to Programming (JavaScript)
Module: 9.1 - Karel Challenges
Problem: 9.1.6 Checkerboard v1
Objective: Write a Karel program that places a checkerboard pattern of beepers on a rectangular world of any size (within Karel’s limits). private int size