Instead of two colors, use four colors repeating. Use (row + col) % 4 to choose from an array of colors. Variation C: User Resizable Canvas In the graphics version, recompute square size on window resize. This is rare for CodeHS but possible in advanced sections. Testing Your Solution Before submitting, test these cases manually:
var rect = new Rectangle(x, y, SQUARE_SIZE, SQUARE_SIZE); rect.setColor(color); rect.setFilled(true); add(rect); 9.1.7 Checkerboard V2 Codehs
square.setColor(square.getFillColor()); Sometimes students write a complex condition like ((row % 2 == 0 && col % 2 == 0) || (row % 2 != 0 && col % 2 != 0)) . This is logically correct but verbose and error-prone. Stick with (row + col) % 2 . Advanced Variations of 9.1.7 Checkerboard V2 Variation A: Diamond or Hexagonal Checkerboard Some "V2" extensions require non-square patterns. The parity rule still applies, but you might need to offset odd rows. Example: staggered rows like a brick wall. Instead of two colors, use four colors repeating
If row % 2 == 1 , start with the opposite color. Equivalent to: This is rare for CodeHS but possible in advanced sections
console.log(line);
private static final int NUM_ROWS = 8; private static final int NUM_COLS = 8;