Skip to content

Instantly share code, notes, and snippets.

@elevenpassin
Created October 25, 2017 17:24
Show Gist options
  • Save elevenpassin/2b5151baaafd21b1c1069f503a2b58c8 to your computer and use it in GitHub Desktop.
Save elevenpassin/2b5151baaafd21b1c1069f503a2b58c8 to your computer and use it in GitHub Desktop.
/*
A program that creates a string that represents an 8 x 8 grid, using newline characters to separate lines.
At each position of the grid there is either a space or a "#" character.
The characters printed should represent a chessboard.
*/
function printChessBoard(size){
let odd = false;
for(var i=0; i < size; i++){
let newline = '';
for(var j=0; j < size/2; j++){
newline += odd ? ' #' : '# '
}
odd = !odd;
console.log(newline);
}
}
module.exports = {
printChessBoard : printChessBoard
}
/*
A program that creates a string that represents an 8 x 8 grid, using newline characters to separate lines.
At each position of the grid there is either a space or a "#" character.
The characters printed should represent a chessboard.
*/
function printChessBoard(size){
let odd = false;
for(var i=0; i < size; i++){
let newline = '';
for(var j=0; j < size/2; j++){
newline += odd ? ' #' : '# '
}
odd = !odd;
console.log(newline);
}
}
module.exports = {
printChessBoard : printChessBoard
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment