add(rect);
To fix the common autograder "assignment" error, you must first create a grid of zeros and then use nested loops to change the top and bottom three rows to grid[row][col] = 1 Need help with Checkerboard v2 or applying the modulus operator for alternating patterns?
function start() var squareSize = 50; var numRows = 8; var numCols = 8; for (var row = 0; row < numRows; row++) for (var col = 0; col < numCols; col++) var x = col * squareSize; var y = row * squareSize;
Use (row + col) % 2 === 0 to determine color. 916 checkerboard v1 codehs fixed
: Explicitly setting grid[i][j] = 1 for the required rows rather than just printing the final output. 2. Common Errors in Initial Attempts
✅ Corrected the row/column offset logic. ✅ Ensured the pen colors switch perfectly every other square. ✅ Fixed the positioning so the board starts exactly at the corner.
At first glance, a checkerboard appears trivial. It is simply a grid of alternating red and black squares. A student’s first instinct is often to "hard code" the solution: draw a red square, then a black square, then a red square, and manually position them one by one. However, the "916" specification usually implies a large grid (likely 8x8 or similar dimensions), making hard-coding impractical and tedious. The "fixed" solution abandons the manual approach in favor of automation, using nested loops to traverse the rows and columns. add(rect); To fix the common autograder "assignment" error,
By adding the current row index to the current column index, you create a pattern that perfectly maps to a checkerboard grid. Column Index Sum ( row + col ) Sum % 2 (Remainder) Value Placed 0 0 0 1 1 0 2 0 1 0 1 1 1 0
var xPos = c * SQUARE_DIMENSION; : This ensures that as the column ( c ) increases, the square moves to the right.
# Reset X for new row x = -200
The set_canvas_color and create_canvas functions are used to initialize the canvas with a white background. The rect function is used to draw each square, and the fill function is used to set the color of each square.
# Starting position (Bottom-left or Top-left depending on preference) # Here we start from top-left for standard drawing order start_x = -200 start_y = 200
Here are some tips and variations to help you improve your solution: ✅ Fixed the positioning so the board starts
add(rect);
To fix the common autograder "assignment" error, you must first create a grid of zeros and then use nested loops to change the top and bottom three rows to grid[row][col] = 1 Need help with Checkerboard v2 or applying the modulus operator for alternating patterns?
function start() var squareSize = 50; var numRows = 8; var numCols = 8; for (var row = 0; row < numRows; row++) for (var col = 0; col < numCols; col++) var x = col * squareSize; var y = row * squareSize;
Use (row + col) % 2 === 0 to determine color.
: Explicitly setting grid[i][j] = 1 for the required rows rather than just printing the final output. 2. Common Errors in Initial Attempts
✅ Corrected the row/column offset logic. ✅ Ensured the pen colors switch perfectly every other square. ✅ Fixed the positioning so the board starts exactly at the corner.
At first glance, a checkerboard appears trivial. It is simply a grid of alternating red and black squares. A student’s first instinct is often to "hard code" the solution: draw a red square, then a black square, then a red square, and manually position them one by one. However, the "916" specification usually implies a large grid (likely 8x8 or similar dimensions), making hard-coding impractical and tedious. The "fixed" solution abandons the manual approach in favor of automation, using nested loops to traverse the rows and columns.
By adding the current row index to the current column index, you create a pattern that perfectly maps to a checkerboard grid. Column Index Sum ( row + col ) Sum % 2 (Remainder) Value Placed 0 0 0 1 1 0 2 0 1 0 1 1 1 0
var xPos = c * SQUARE_DIMENSION; : This ensures that as the column ( c ) increases, the square moves to the right.
# Reset X for new row x = -200
The set_canvas_color and create_canvas functions are used to initialize the canvas with a white background. The rect function is used to draw each square, and the fill function is used to set the color of each square.
# Starting position (Bottom-left or Top-left depending on preference) # Here we start from top-left for standard drawing order start_x = -200 start_y = 200
Here are some tips and variations to help you improve your solution: