Skip to main content
added 62 characters in body
Source Link
Paul
  • 321
  • 1
  • 5

I think it's fine as is, though some folks like to return early instead of using a series of if..else. For example:

for(varfunction i=1;i<=100;i++calc(i) {
  if(i % 15 == 0) return "FizzBuzz";
  if(i % 3 == 0) return "Fizz";
  if(i % 5 == 0) return "Buzz";
  return i;
}

for(var i=1;i<=100;i++) {
  console.log(calc(i));
}

I think it's fine as is, though some folks like to return early instead of using a series of if..else. For example:

for(var i=1;i<=100;i++) {
  if(i % 15 == 0) return "FizzBuzz";
  if(i % 3 == 0) return "Fizz";
  if(i % 5 == 0) return "Buzz";
  return i;
}

I think it's fine as is, though some folks like to return early instead of using a series of if..else. For example:

function calc(i) {
  if(i % 15 == 0) return "FizzBuzz";
  if(i % 3 == 0) return "Fizz";
  if(i % 5 == 0) return "Buzz";
  return i;
}

for(var i=1;i<=100;i++) {
  console.log(calc(i));
}
Source Link
Paul
  • 321
  • 1
  • 5

I think it's fine as is, though some folks like to return early instead of using a series of if..else. For example:

for(var i=1;i<=100;i++) {
  if(i % 15 == 0) return "FizzBuzz";
  if(i % 3 == 0) return "Fizz";
  if(i % 5 == 0) return "Buzz";
  return i;
}