916 Checkerboard V1 Codehs Fixed
function start() var squareSize = 50; var numRows = 8; var numCols = 8;for (var row = 0; row < numRows; row++) for (var col = 0; col < numCols; col++) var x = col * squareSize; var y = row * squareSize; var color; if ((row + col) % 2 === 0) color = "red"; else color = "black"; var square = new Rectangle(squareSize, squareSize); square.setPosition(x, y); square.setColor(color); add(square);
The following code represents the "Fixed" solution. It uses a for loop structure which inherently handles the counting, solving the "infinite loop" bug often associated with while loops in this unit.
Language: Python (CodeHS default)
# 916 Checkerboard v1 - Fixed Solution
import turtle
# --- Setup ---
t = turtle.Turtle()
t.speed(0) # Set speed to fastest
t.hideturtle()
# Constants
SIZE = 50 # Size of one square
ROWS = 8
COLS = 8
# Starting position (Bottom-left or Top-left depending on preference)
# Here we start from top-left for standard drawing order
start_x = -200
start_y = 200
# --- Drawing Logic ---
# Use variables to track current position
current_x = start_x
current_y = start_y
# Outer loop for Rows
for i in range(ROWS):
# Inner loop for Columns
for j in range(COLS):
# Determine Color
# If (row + col) is even, draw black. If odd, draw red.
if (i + j) % 2 == 0:
t.color("black")
else:
t.color("red")
# Draw the square
t.begin_fill()
for k in range(4):
t.forward(SIZE)
t.right(90)
t.end_fill()
# Move to the next column position
t.penup()
t.goto(current_x + (j + 1) * SIZE, current_y - i * SIZE)
t.pendown()
# Logic to move the turtle to the start of the next row
# Note: The loop logic handles this via math, or you can update y manually.
# The loop above uses math (j+1)*SIZE to handle x movement automatically.
Create a 8x8 checkerboard using a loop. The checkerboard should have alternating black and white squares.
After implementing the code above, run the program. You should see:
If the board starts with black instead of red, simply swap the colors in the if-else block. 916 checkerboard v1 codehs fixed
The checkerboard problem isn’t just about drawing a pretty pattern. It teaches:
Getting the "916 checkerboard v1 codehs fixed" means you’ve mastered these core programming concepts.
The fixed solution for 9.1.6 Checkerboard (v1) on CodeHS hinges on the simple yet powerful condition (row + col) % 2 == 0. Whether you’re using Java or JavaScript, ensure your loops run correctly, you set filled to true, and you apply the alternating logic precisely. function start() var squareSize = 50; var numRows
Now go ahead — copy the fixed code above, run it, and watch your perfect checkerboard appear. Then celebrate passing the autograder with full points!
Need help with another CodeHS exercise? Check out our guides for 9.1.7, 9.2.3, or 10.3.5 — all with verified fixes.
This report includes the Problem Statement, Algorithm Analysis, the Corrected Code Solution, and a detailed Code Breakdown to ensure the "fixed" requirements are met (specifically addressing the common issue where the code runs infinitely or crashes due to missing decrement logic). The following code represents the "Fixed" solution
Before we jump to the "fixed" code, let’s break down the assignment’s requirements:
The most common "non-fixed" issues students encounter: