Last active
July 22, 2020 18:39
-
-
Save faddah/c7190f96fef19cb6fb19c2e23b61313d to your computer and use it in GitHub Desktop.
JavaScript FizzBuzz 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
'use strict'; | |
/* | |
* Complete the 'fizzBuzz' function below. | |
* | |
* The function accepts INTEGER n as parameter. | |
*/ | |
function fizzBuzz(n) { | |
if(typeof n !== 'number') { | |
console.log("The input must be of Type Number.") | |
return | |
} | |
let result = ''; | |
for(let i = 1; i < n + 1; i++) { | |
if ((i % 3 == 0) && (i % 5 == 0)) { | |
result.concat('\n', 'FizzBuzz') | |
} | |
else if (i % 5 == 0) { | |
result.concat('\n', 'Buzz') | |
} | |
else if (i % 3 == 0) { | |
result.concat('\n', 'Fizz'); | |
} | |
else { | |
result.concat('\n', i); | |
} | |
}; | |
return console.log(result); | |
} | |
function main() { | |
const n = parseInt(readLine().trim(), 10); | |
fizzBuzz(n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment