Created
October 15, 2015 23:46
-
-
Save chtzvt/a4d9b3cc57a3846710d1 to your computer and use it in GitHub Desktop.
FizzBuzz example
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
// Test the divisibility of numbers from 1-100. | |
for (var i = 1; i <= 100; i++) { | |
// Is the number evenly divisible by both 3 and 5? | |
if((i % 3 === 0) && (i % 5 === 0)){ | |
console.log('fizzbuzz'); | |
// No? Then let's see whether it's divisible by 3. | |
} else if(i % 3 === 0) { | |
console.log('fizz'); | |
// Still no? Let's try 5, then. | |
} else if (i % 5 === 0){ | |
console.log('buzz'); | |
} else { | |
// No luck? Just write it to the console, then. | |
console.log(i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment