Skip to content

Instantly share code, notes, and snippets.

@cefn
Created August 22, 2021 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cefn/b57cc40e35e65401f98790df58c96350 to your computer and use it in GitHub Desktop.
Save cefn/b57cc40e35e65401f98790df58c96350 to your computer and use it in GitHub Desktop.
FizzBuzz Cefn
for (let x = 1; x <= 100; x++) {
console.log(
`${x % 3 === 0 ? "Fizz" : ""}${x % 5 === 0 ? "Buzz" : ""}` || x.toString()
);
}
@cefn
Copy link
Author

cefn commented Aug 22, 2021

I can't decide if I prefer the more explicit...

for (let x = 1; x <= 100; x++) {
  let output = `${x % 3 === 0 ? "Fizz" : ""}${x % 5 === 0 ? "Buzz" : ""}`;
  if (output === "") {
    output = x.toString();
  }
  console.log(output);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment