Exerpad
Exercise 9 · Chapter: Pixel ProjectsOptional+50 XP

Concentric Squares

Read a number N from input and create an N x N grid with concentric square rings that alternate between two colors.

Each cell's ring number is its minimum distance to any edge: Math.min(row, col, N - 1 - row, N - 1 - col).

Use "coral" for even rings (0, 2, 4...) and "teal" for odd rings (1, 3, 5...).

Don't change the console.log statements at the bottom.

Expected output
8
coral
teal
coral
Need a hint?
3 available · costs 5 XP each
javascript
let n = Number(prompt());
let grid = [];
// Create N x N grid
// ring = Math.min(row, col, n - 1 - row, n - 1 - col)
// Even ring: "coral", odd ring: "teal"


let __grid__ = grid;

// Don't change below this line
console.log(grid.length);
console.log(grid[0][0]);
console.log(grid[1][1]);
console.log(grid[2][2]);
Output
Run your code to see the output here.