Created
June 10, 2019 02:18
-
-
Save KameronKales/bd01ea0d6f9d2751fc6ad7615784e549 to your computer and use it in GitHub Desktop.
FizzBuzz Node 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
// Write a program that prints the numbers | |
//from 1 to 100. But for multiples of three print “Fizz” | |
// instead of the number and for the multiples of five print “Buzz”. | |
// For numbers which are multiples of both three and five print “FizzBuzz”." | |
var i = 0; | |
for (i; i < 101; i++) { | |
Fizz = 3; | |
Buzz = 5; | |
check_int({ i, Fizz, Buzz }, function(response) { | |
console.log(response); | |
}); | |
} | |
function check_int({ i, Fizz, Buzz }, aCallback) { | |
fizz_result = i / Fizz; | |
buzz_result = i / Buzz; | |
if (fizz_result % 1 === 0 && buzz_result % 1 === 0) { | |
aCallback(`The number ${i} is divisable by 3 & 5, FizzBuzz`); | |
} else if (fizz_result % 1 === 0) { | |
aCallback(`The number ${i} is divisable by 3 but not 5, Fizz`); | |
} else if (buzz_result % 1 === 0) { | |
aCallback(`The number ${i} is divisable by 5 but not 3, Buzz`); | |
} else { | |
aCallback(`The number ${i} is not divisable by 3 or 5, ${i}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment