top of page

916 Checkerboard V1 Codehs Fixed Jun 2026

: The program alternates between placing a "Ball-first" row and a "Blank-first" row.

public class Checkerboard extends JPanel public Checkerboard() setPreferredSize(new Dimension(800, 800)); setBackground(Color.WHITE);

# Define the square size square_size = canvas_width // 8

Finally, pass your completed grid to the provided print_board function to display the result.

Mastering CodeHS 9.1.6: Checkerboard v1 Complete Solution Guide 916 checkerboard v1 codehs fixed

/* * This program draws a checkerboard pattern. * The "Fixed" version ensures that rows alternate * regardless of the grid dimensions. */

/* This program draws a checkerboard pattern using nested loops. */ var RADIUS = 20; var DIAMETER = RADIUS * 2; function start() // Outer loop for the vertical rows (Y-axis) for (var row = 0; row < getHeight() / DIAMETER; row++) // Inner loop for the horizontal circles (X-axis) for (var col = 0; col < getWidth() / DIAMETER; col++) var x = col * DIAMETER + RADIUS; var y = row * DIAMETER + RADIUS; // Logic to determine color based on grid position if ((row + col) % 2 == 0) drawCircle(x, y, Color.red); else drawCircle(x, y, Color.black); function drawCircle(x, y, color) var circle = new Circle(RADIUS); circle.setPosition(x, y); circle.setColor(color); add(circle); Use code with caution. Breakdown of the Fix

# Loop through each row for row in range(8): # Loop through each column for col in range(8): # Calculate the color of the square if (row + col) % 2 == 0: fill(WHITE) else: fill(BLACK)

Python (CodeHS default)

(i + j) % 2 == 0 divides the sum of the indices by 2. If there is no remainder, the position is even, assigning a 0 . Otherwise, it assigns a 1 .

function at the very end to display your final, modified grid.

Your primary helper function needs to handle moving across a row while dropping balls every second space. javascript

for i in range( 8 ): for j in range( 8 ): if i < 3 or i > 4 : grid[i][j] = 1 Use code with caution. Copied to clipboard : The program alternates between placing a "Ball-first"

: Using getWidth() / DIAMETER ensures that your checkerboard fills the screen regardless of how big the canvas is. Pro-Tip for CodeHS Debugging

: Do not define your print_board function inside another function or loop; it should be at the top level of your script.

# --- Setup --- t = turtle.Turtle() t.speed(0) # Set speed to fastest t.hideturtle()

# Inner loop for Columns for j in range(COLS): * The "Fixed" version ensures that rows alternate

bottom of page