Created
December 4, 2017 13:21
-
-
Save imparvez/6a3935b7a10323227cb2145febd76870 to your computer and use it in GitHub Desktop.
Print out all the numbers from 1 to 100. But for every number divisible by 3 print replace it with the word “Fizz,” for any number divisible by 5 replace it with the word “Buzz” and for a number divisible by both 3 and 5 replace it with the word “FizzBuzz.”
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
function minefizzBuzz(number){ | |
if(number % 3 === 0 && number % 5 === 0) { | |
return "FizzBuzz" | |
} else if( number % 5 === 0) { | |
return "Buzz" | |
} else if(number % 3 === 0 ) { | |
return "Fizz" | |
} else { | |
return number; | |
} | |
} // For ONE number | |
function updatedfizzBuzz(n) { | |
let result = []; | |
for(let i = 1; i <= n; i++) { | |
let add = ''; | |
if( i % 3 === 0) { add += 'Fizz' } | |
if( i % 5 === 0) { add += 'Buzz' } | |
if(add === '') { result.push(i) } | |
else { result.push(add) } | |
} | |
return result; | |
} // For | |
console.log(minefizzBuzz(10)); | |
console.log(updatedfizzBuzz(10)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment