Created
May 17, 2018 09:03
-
-
Save Taelkir/3315c868f59dd0414871274d4c8ff6ff to your computer and use it in GitHub Desktop.
JavaScript FizzBuzz
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
/* | |
** | |
*** Came across this article during my learning JS travels : https://blog.codinghorror.com/why-cant-programmers-program/ | |
*** Decided to have a go. Took about 15 minutes to get perfect. | |
*** I've been learning HTML/CSS/JS for a day each week for about 5 months. | |
** | |
*/ | |
for (i = 0; i<100; i++) { | |
let toPrint = i+1; | |
// Multiple of both 3 and 5? | |
if ((i+1)%3 === 0 && (i+1)%5 === 0) { | |
toPrint = "FizzBuzz"; | |
// Multiple of 3? | |
} else if ((i+1)%3 === 0) { | |
toPrint = "Fizz"; | |
// Multiple of 5? | |
} else if ((i+1)%5 === 0) { | |
toPrint = "Buzz"; | |
} | |
// If the number is a multiple, print the correct word. If not, just print the number. | |
console.log(toPrint); | |
} // End for loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment