Skip to content

Instantly share code, notes, and snippets.

@LucasRizzotto
Created February 4, 2015 03:22
Show Gist options
  • Save LucasRizzotto/db6911864b0930113409 to your computer and use it in GitHub Desktop.
Save LucasRizzotto/db6911864b0930113409 to your computer and use it in GitHub Desktop.
My Chessboard Exercise solution from the Eloquent JS book.
/* This is the way I found to solve it. There are probably easier ways to do this. I am a total beginner */
var boardwidth = 8, boardheight = 5, board = "";
for ( i = 0 ; i < boardheight ; i++ ) {
for ( f = 0 ; f < boardwidth ; f++ ) {
if ( f % 2 === 0 )
board += " ";
else
board += "#";
}
if ( i % 2 === 0) {
board += "\n ";
}
else {
board += "\n";
}
}
console.log(board)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment