Today, we will write a function that forms a chessboard. You can find the exercise in the Eloquent Javascript book (3rd edition, chapter 2; Program Structure).
Write a program that creates a string that represents an 8×8 grid, using newline characters to separate lines. At each position of the grid there is either a space or a “#” character. The characters should form a chessboard.
Passing this string to console.log
should show something like this:
## ## ## #
## ## ## ##
## ## ## #
## ## ## ##
## ## ## #
## ## ## ##
## ## ## #
## ## ## #
Let’s start writing our function that takes a number as a parameter and generates a grid of the given size.
#technology #programming #algorithms #javascript #string