Skip to content

Instantly share code, notes, and snippets.

@Taelkir
Created May 17, 2018 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Taelkir/3315c868f59dd0414871274d4c8ff6ff to your computer and use it in GitHub Desktop.
Save Taelkir/3315c868f59dd0414871274d4c8ff6ff to your computer and use it in GitHub Desktop.
JavaScript FizzBuzz
/*
**
*** 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