Created
December 16, 2023 09:11
-
-
Save hiteshsahu/0473e74ff906f7061d7954d87069eb43 to your computer and use it in GitHub Desktop.
FizzBuzz Javascript
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'; | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf-8'); | |
let inputString = ''; | |
let currentLine = 0; | |
process.stdin.on('data', function(inputStdin) { | |
inputString += inputStdin; | |
}); | |
process.stdin.on('end', function() { | |
inputString = inputString.split('\n'); | |
main(); | |
}); | |
function readLine() { | |
return inputString[currentLine++]; | |
} | |
/* | |
* Complete the 'fizzBuzz' function below. | |
* | |
* The function accepts INTEGER n as parameter. | |
*/ | |
function fizzBuzz(n) { | |
// Write your code here | |
for(let i=1; i<=n; i++){ | |
const isMultipleOf3 = i%3 ==0 | |
const isMultipleOf5 = i%5 ==0 | |
if(isMultipleOf3 && isMultipleOf5 ) print("FizzBuzz") | |
else if(isMultipleOf3 && !isMultipleOf5) print("Fizz") | |
else if(!isMultipleOf3 && isMultipleOf5) print("Buzz") | |
else print(i) | |
} | |
} | |
function print(message){ | |
console.log(message) | |
} | |
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