John Landon John Landon - 19 days ago 5
Javascript Question

Ignore if x < 50, unless x = 100. How would this be done?

I am trying to make it something like:

if (x > 50) return unless {
if (x = 100) {
console.log("x is equal to 100");
}


I know that is not at all how you are supposed to use unless, but I am trying to make it so that if x is over 50, then it should be ignored unless it is 100, and if it is 100, then it should run a command.

Answer

You don't quite describe what you want to do in the various cases, so here's the most generic code:

if (x == 100)
{
    // do whatever you want to do when x is 100
}
else if (x > 50)
{
    // do whatever you want to do when x is (strictly) greater than 50, but not 100
}
else
{
    // do whatever you want to do in all other cases, i.e. when x is less than or equal to 50
}