9.1.6 Checkerboard V1 Codehs Jun 2026

# Determine the color based on the sum of row and col indices # If the sum is even, it's one color; if odd, it's the other. if (row + col) % 2 == 0: square.set_color(Color.black) else: square.set_color(Color.white)

If you add the current row index ( r ) and column index ( c ), the sum alternates between even and odd numbers across the entire grid: Row 0, Col 0 Row 0, Col 1 Row 1, Col 0 Row 1, Col 1

if (frontIsClear()) move(); col++; else break; 9.1.6 checkerboard v1 codehs

The line if ((r + c) % 2 === 0) uses the modulo operator to see if there is a remainder when dividing by 2.

Notes:

The "9.1.6 Checkerboard v1" exercise in CodeHS is a classic challenge designed to test your mastery of and 2D arrays (or grids). Creating a checkerboard pattern requires a logical approach to alternating colors based on row and column indices.

Core observation: parity (even/odd) of row+column determines which symbol to place. # Determine the color based on the sum

Are you using the version or the Java/Python version of CodeHS?


Работает на: Amiro CMS