private static final int SQUARE_SIZE = 50; private static final int ROWS = 8; private static final int COLUMNS = 8;
If you’ve landed on this article, chances are you’re stuck on the "9.1.6 Checkerboard (v1)" problem in the CodeHS Java (or sometimes JavaScript Graphics) course. You’ve tried writing the code, but the checkerboard isn’t rendering correctly—maybe the colors are wrong, the rows aren’t alternating, or the squares aren’t aligned. 916 checkerboard v1 codehs fixed
public void run() for (int row = 0; row < ROWS; row++) for (int col = 0; col < COLUMNS; col++) int x = col * SQUARE_SIZE; int y = row * SQUARE_SIZE; GRect square = new GRect(x, y, SQUARE_SIZE, SQUARE_SIZE); square.setFilled(true); // Checkerboard logic: alternate color based on (row + col) % 2 if ((row + col) % 2 == 0) square.setColor(Color.RED); // or Color.GRAY else square.setColor(Color.BLACK); add(square); private static final int SQUARE_SIZE = 50; private