output fizzbuzz but with 4 and 6 in typescript

Here's an implementation of FizzBuzz with additional checks for 4 and 6 in TypeScript:

index.ts
for (let i = 1; i <= 100; i++) {
  let output = "";
  if (i % 4 === 0) {
    output += "4";
  }
  if (i % 6 === 0) {
    output += "6";
  }
  if (i % 3 === 0) {
    output += "Fizz";
  }
  if (i % 5 === 0) {
    output += "Buzz";
  }
  console.log(output || i);
}
264 chars
17 lines

In this implementation, we check for divisibility by 4 and 6 before checking for divisibility by 3 and 5. If a number is divisible by 4 or 6, we add "4" or "6" to the output string respectively. If a number is divisible by 3 or 5, we add "Fizz" or "Buzz" to the output string respectively. If none of these conditions are met, we log the number itself.

gistlibby LogSnag