Loopy Challenge

You will be writing a program that prints the numbers from 100 to 200 to the console, with three exceptions:

  • If the number is a multiple of 3, print the string "Loopy" instead of the number.
  • If the number is a multiple of 4, print the string "Lighthouse" instead of the number.
  • If the number is a multiple of both 3 and 4, print the string "LoopyLighthouse" instead of the number.
for (let num = 100; num <= 200; num++) {
  if (num % 3 === 0) {
    console.log("Loopy");
  }
  else if (num % 4 === 0) {
    console.log("Lighthouse");
  }
  else if (num % 3 === 0 && num % 4 === 0) {
    console.log("LoopyLighthouse");
  }
  else {
    console.log(num);
  }
}

What seem to be the problem? I’ve been at this for about an hour and I can’t find the solution.

what do you think is going to be true first between these two?

Loopy (first one) will come true, the second one won’t run because they have the same value?
What do I do?

you need to refactor your code considering the order in which the conditions are checked

alternatively, you can refactor it all to work with a single console.log, building a string depending on how the number is divisible.

For your own research, this is a FizzBuzz type algorithm