9.1.7 Checkerboard V2 Codehs !!better!! -
If the row index is odd, the pattern must start with Color B.
Create a grid of filled rectangles (or squares) that alternate between two colors.
Building the program in CodeHS is all about mastering nested loops and using the modulo operator ( % ) to alternate colors efficiently. 9.1.7 Checkerboard V2 Codehs
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.
import java.util.Scanner;
The exercise on CodeHS is a classic test of your ability to combine loops, conditionals, and modular arithmetic. The single most important takeaway is the parity rule : (row + column) % 2 .
Using setFilled(true) alone might leave a tiny border. Some CodeHS exercises expect setFilled(true) without setColor for the outline. If gaps appear, set the outline color to match the fill color: If the row index is odd, the pattern must start with Color B
Instead of cluttering your loops, write a function dedicated to drawing a single square. javascript
In many Karel-based versions of this task, the difficulty lies in the "turnaround." Once Karel reaches the end of a row, the program must determine if there is another row above it. If so, Karel must turn, move up, and position itself to face the opposite direction to begin the next line. This requires careful use of Some "V2" extensions require non-square patterns