V1 Codehs: 9.1.6 Checkerboard
The outer loop ( row ) handles the vertical movement, while the inner loop ( col ) handles the horizontal movement. This ensures every single "coordinate" on the board is visited. 2. The Modulo Operator (%) The code (row + col) % 2 == 0 is the engine of the program. At (0,0) , the sum is 0. 0 % 2 is 0 (Even). At (0,1) , the sum is 1. 1 % 2 is 1 (Odd). At (1,0) , the sum is 1. 1 % 2 is 1 (Odd). At (1,1) , the sum is 2. 2 % 2 is 0 (Even).
In CodeHS, simply saying "Row 1" doesn't tell the computer where to draw on the screen. You must multiply the row or col by the sideLength of the square to get the actual pixel position Common Pitfalls
Are you having trouble with a in your CodeHS console, or does the logic of the modulo operator make sense now? 9.1.6 checkerboard v1 codehs
Understanding the simple logic in v1—building rows and appending them to a list—is crucial for tackling those more complex patterns. Mastering this foundational exercise sets you up for success in the rest of the project. Good luck, and happy coding!
You need one loop for the rows and another loop for the columns. For each row (y-position), you will iterate through all columns (x-positions). The outer loop ( row ) handles the
public void run() // Set the canvas size setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
This public link is valid for 7 days and shares a thread, including any personal information you added. This link or copies made by others cannot be deleted. If you share with third parties, their policies apply. Can’t copy the link right now. Try again later. The Modulo Operator (%) The code (row +
is a foundational exercise designed to teach nested loops, 2D arrays (or grid systems), and conditional logic.
To create the in CodeHS, you need to use nested for loops to place circles in a grid pattern . 🏁 Core Logic The goal is to create an grid of circles. The outer loop controls the rows (vertical movement). The inner loop controls the columns (horizontal movement). The spacing is determined by the radius of the circle. 💻 Solution Code javascript
The ultimate goal is a board that looks something like this:
The for row in range(NUM_SQUARES): loop starts at row 0. Before moving to row 1, it triggers the inner for col in range(NUM_SQUARES): loop, which runs through columns 0 to 7. This ensures every single grid position is visited. Calculating