Skip to content

Instantly share code, notes, and snippets.

@rodrigolira
Last active June 16, 2018 21:02
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 rodrigolira/a8935f2905d5004fec679e2b147984f5 to your computer and use it in GitHub Desktop.
Save rodrigolira/a8935f2905d5004fec679e2b147984f5 to your computer and use it in GitHub Desktop.
Implementing the FizzBuzz algorithm in Javascript
// Create a funcion that will receive an integer number as a parameter and output to the log every number from 1 to the parameter.
// For each number divisible by 3, it should log the word "Fizz" instead of the number.
// For each number divisible by 5, it should log the word "Buzz" instead of the number.
// For each number divisible by 3 and 5, it should log the word "FizzBuzz" instead of the number.
function fizzBuzz(num) {
for (var i = 1; i <= num; i++) {
if (i % 15 == 0) console.log("FizzBuzz")
else if (i % 3 == 0) console.log("Fizz")
else if (i % 5 == 0) console.log("Buzz")
else console.log(i);
}
}
fizzBuzz(45);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment