Created
March 26, 2018 15:46
-
-
Save 0xCourtney/3ce35217da82ff288c6f9f3049a9b947 to your computer and use it in GitHub Desktop.
FizzBuzz - Toy Problem
This file contains hidden or 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
// FizzBuzz | |
// write a function that takes in one number. | |
// Starting at 1, console log every number up to the number passed in. | |
// If the number being logged is divisible by 3 log 'Fizz' instead. | |
// If the number is divisible by 5 we will log 'Buzz' instead. | |
// If they are divisible by both 3 and 5 we will log 'FizzBuzz' | |
function fizzBuzz(num) { | |
for (let i = 1; i <= num; i++) { | |
if (i % 3 === 0 && i % 5 === 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(15); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment