Last active
June 5, 2017 17:42
-
-
Save Dylan-Thomson/1810fec1d5af80ee1c2761f9094d604e to your computer and use it in GitHub Desktop.
ChessBoard - Eloquent JavaScript Chapter 2 Solution
This file contains hidden or 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
| function chessBoard(size) { | |
| var board = ""; | |
| for (var y = 0; y < size; y++) { | |
| for (var x = 0; x < size; x++) { | |
| if ((x + y) % 2 == 0) | |
| board += "#"; | |
| else | |
| board += " "; | |
| } | |
| board += "\n"; | |
| } | |
| return board; | |
| } | |
| // Output for chessBoard(8) | |
| // # # # # | |
| // # # # # | |
| // # # # # | |
| // # # # # | |
| // # # # # | |
| // # # # # | |
| // # # # # | |
| // # # # # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment