Show how to do this in if you are in the Nitro/Java course
What or failed test case is the autograder showing?
What or failing test case is CodeHS showing?
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 . 9.1.7 Checkerboard V2 Codehs
for i in range(8): for j in range(8): if (i + j) % 2 == 0: board[i][j] = 1 Use code with caution. Copied to clipboard
First, you must create a grid object using the Grid class. The dimensions are typically defined by the constants NUM_ROWS and NUM_COLS . javascript var grid = new Grid(NUM_ROWS, NUM_COLS); Use code with caution. Copied to clipboard 2. Nest loops for iteration
In CodeHS graphics (using the GraphicsProgram or Turtle ), you will use add(new Rectangle(x, y, width, height)) or similar methods. Show how to do this in if you
public class CheckerboardV2 extends GraphicsProgram
// Draw the checkerboard for (var row = 0; row < rows; row++) for (var col = 0; col < cols; col++) // Alternate between light and dark colors var color = (row + col) % 2 === 0 ? 'lightgray' : 'gray'; drawSquare(col * squareSize, row * squareSize, color);
To create an efficient solution, you need to identify the mathematical pattern. The single most important takeaway is the parity
// Function to draw a square function drawSquare(x, y, color) ctx.fillStyle = color; ctx.fillRect(x, y, squareSize, squareSize);
It looks like you're asking for the solution or an explanation for the problem (Exercise 9.1.7) on CodeHS.
: Avoid manually typing out all 64 values. The exercise is designed to test your mastery of loops. specific error message you're seeing, or should we walk through the print_board function
Subscribe to get all the latest tried & tested treats delivered straight to you!
Browse
Diets
About Texanerin Baking
Here you’ll find meticulously tested dessert recipes with both traditional and dietary-friendly options, including gluten-free, dairy-free, and vegan adaptations that don’t compromise on taste.
Subscribe to get all the latest recipes in your inbox!