Created
February 4, 2015 03:22
-
-
Save LucasRizzotto/db6911864b0930113409 to your computer and use it in GitHub Desktop.
My Chessboard Exercise solution from the Eloquent JS book.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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