Skip to content

Instantly share code, notes, and snippets.

@andrewatts85
Last active August 29, 2015 14:19
Show Gist options
  • Save andrewatts85/fe019213fc3e56d06fca to your computer and use it in GitHub Desktop.
Save andrewatts85/fe019213fc3e56d06fca to your computer and use it in GitHub Desktop.
EJS: Chess Board Excercise
//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 chess board.
//When you have a program that generates this pattern, define a variable size = 8 and change the program so that it works for any size, outputting a grid of the given width and height.
function checkers(size) {
var line = "";
for (var i=0; i<size; i++) {
for (var j=0; j<size; j++) {
if (j%2 === 0) line += " ";
else line += "#";
}
console.log(line);
if (i%2 === 0) line = " ";
else line = "";
}
}
checkers(8);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment