Read the question, write TypeScript on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Classic FizzBuzz for 1..n.
Examples
Input
5
Output
1 2 Fizz 4 Buzz
Hint
- %15 first
Show correct code
Peek only after you have tried. You can still Check your own version.
const n: number = Number(readLine());
for (let i = 1; i <= n; i++) {
if (i % 15 === 0) console.log('FizzBuzz');
else if (i % 3 === 0) console.log('Fizz');
else if (i % 5 === 0) console.log('Buzz');
else console.log(i);
}
main.tstsc · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.