Last active
October 14, 2018 12:45
-
-
Save dansayo/cdb43a7dd7d045a9319f07557e97e0dd to your computer and use it in GitHub Desktop.
Javascript exercises answered from http://eloquentjavascript.net/index.html
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
// prints out a right triangle made out of hash tags | |
let output = ""; | |
for (x = 1; x < 8; x = x + 1) { | |
output += "#"; | |
console.log(output); | |
} |
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
// if divisible by 3, Fizz, if by 5, Buzz, if both FizzBuzz; | |
// otherwise just print the number | |
for (let i = 1; i < 101; i = i + 1) { | |
output = ""; | |
if (i % 3 == 0) output = "Fizz"; | |
if (i % 5 == 0) output += "Buzz"; | |
if (output) console.log(output); | |
else console.log(i); | |
} |
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
// draw a checkered board with given height and width | |
const board = function(height,width) { | |
let square = ""; | |
let board = ""; | |
for(let h = 0; h < height; h = h + 1) { | |
if (h%2) square="#"; else square=" "; | |
line = ""; | |
for(let w = 0; w < width; w = w + 1) { | |
line += square; | |
if (square=="#") square=" "; else square="#"; | |
} | |
line += '\n'; | |
board += line; | |
} | |
return board; | |
} | |
console.log(board(8,8)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment