-
-
Save LaisGalvao/c5e94e36988584b9b59fbb0dac4894b0 to your computer and use it in GitHub Desktop.
FizzBuzz Typescript Sample
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: string = ''; | |
let inputLines: string[] = []; | |
let currentLine: number = 0; | |
process.stdin.on('data', function(inputStdin: string): void { | |
inputString += inputStdin; | |
}); | |
process.stdin.on('end', function(): void { | |
inputLines = inputString.split('\n'); | |
inputString = ''; | |
main(); | |
}); | |
function readLine(): string { | |
return inputLines[currentLine++]; | |
} | |
/* | |
* Complete the 'fizzBuzz' function below. | |
* | |
* The function accepts INTEGER n as parameter. | |
*/ | |
function fizzBuzz(n: number): void { | |
let i: number; | |
for (i=1; i <=n; i++){ | |
if (i % 3 === 0 && i % 5 === 0) { | |
console.log('FizzBuzz') | |
} | |
if (i % 3 === 0 && i % 5 !== 0) { | |
console.log('Fizz') | |
} | |
if (i % 3 !== 0 && i % 5 === 0) { | |
console.log('Buzz') | |
} | |
if (i % 3 !== 0 && i % 5 !== 0) { | |
console.log(i) | |
} | |
} | |
} | |
function main() { | |
const n: number = parseInt(readLine().trim(), 10); | |
fizzBuzz(n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment