set canvas size (e.g., 400 x 400)
set number of rows/cols = 8
square_size = canvas_width / 8

for row from 0 to 7: for col from 0 to 7: x = col * square_size y = row * square_size if (row + col) % 2 == 0: color = RED else: color = BLACK draw square at (x, y) with size square_size, fill color

Once you have mastered 9.1.6 Checkerboard v1, challenge yourself with these modifications:

If you are working through the CodeHS Java course (specifically the "9.1.6 Checkerboard v1" problem), you have likely encountered a classic programming challenge: creating a checkerboard pattern. This exercise is a rite of passage for learning nested loops, conditional logic, and graphical object placement.

In this article, we will break down exactly what the 9.1.6 Checkerboard v1 assignment asks for, how to approach the logic, and provide a fully commented solution.

Example (pseudocode):

for r in 0..7:
    line = ""
    for c in 0..7:
        if (r + c) % 2 == 0:
            line += "#"
        else:
            line += " "
    print(line)
  • Graphical (canvas/turtle) output:

  • Using helper functions (CodeHS libraries):

  • The Modulo Operator (%):

  • Setting the Color:

  • Grid Integration:

  • >