Skip to content

Instantly share code, notes, and snippets.

@chtzvt
Created October 15, 2015 23:46
Show Gist options
  • Save chtzvt/a4d9b3cc57a3846710d1 to your computer and use it in GitHub Desktop.
Save chtzvt/a4d9b3cc57a3846710d1 to your computer and use it in GitHub Desktop.
FizzBuzz example
// 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