If you’re working through the CodeHS Java (or JavaScript) Graphics track, you’ve probably reached Exercise 9.1.7: Checkerboard V2. 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 this post, I’ll break down the problem, explain the logic, and provide a clean solution so you can move forward with confidence.
The "V2" autograder on CodeHS is stricter. It may check for: 9.1.7 Checkerboard V2 Codehs
Pro Tip: Run your code with a board size of 4x4 first to verify the pattern before scaling to 8x8.
Expected 4x4 pattern:
R B R B
B R B R
R B R B
B R B R
If you are navigating the CodeHS Java (or JavaScript) curriculum, particularly in the "Advanced Arrays" or "Graphics" sections, you have likely encountered Exercise 9.1.7: Checkerboard V2. If you’re working through the CodeHS Java (or
At first glance, it seems simple: draw a checkerboard. However, this problem is a classic exercise in nested loops, conditional logic, coordinate math, and efficient rendering. It strips away the fluff of game logic and focuses on the core visual structure of an 8x8 grid.
This article will break down the problem, explore the common pitfalls, provide step-by-step solutions in both Java (Console/Graphics) and JavaScript (Web Graphics), and explain the underlying principles so you can truly master the concept. Pro Tip: Run your code with a board
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.
Bad Code:
if (row === 0 && col === 0) square.setColor("red");
if (row === 0 && col === 1) square.setColor("black");
// ... 62 more horrendous lines
Fix: Use the (row + col) % 2 formula. Never hardcode each tile.
The goal is typically to draw an 8x8 checkerboard with alternating black and red squares (or another color pair).