9.1.6 Checkerboard V1 Codehs [WORKING]

Never try to move() if you are at a wall. This will cause a Karel crash.

The goal of the exercise in CodeHS is to create a 2D array representing an

The outer loop ( row ) tells the program to start at the top and move down. For every single row, the inner loop ( col ) runs across from left to right. This ensures every single coordinate on the grid is visited. 2. The Modulo Operator (%) The line (row + col) % 2 == 0 is the "brain" of the code. % 2 finds the remainder when divided by 2. If the remainder is 0 , the number is even.

: Used to detect even and odd numbers to alternate colors. Coordinate Mapping : Calculating the precise pixel coordinates for drawing each square. Complete Solution Code 9.1.6 checkerboard v1 codehs

You need to create a checkerboard pattern (alternating black and red squares) using a grid of squares, typically with n rows and n columns (often n = 8 for a standard checkerboard).

function start() // Create checkerboard pattern var row = 1; while (true) for (var i = 0; i < 100; i++) // max columns if (row % 2 == 1) if (i % 2 == 0) putBeeper(); else if (i % 2 == 1) putBeeper();

(Invoking related search terms)

The most efficient way to determine the color of a square at position (row, col) is to check if the sum of the row and column indices is even or odd. : One color (e.g., 0 ). Odd sum ( row + col % 2 != 0 ) : The other color (e.g., 1 ). Implementation Steps

Happy coding!

let board = [];

Completing "Checkerboard, v1" teaches you several key concepts:

: Create an empty list called board and fill it with eight rows of eight zeros.