0

I made the following statement:

if (command !== "define" || (command !== "add") || (command !== "remove")) throw "ERROR 1";

It's inside a try if statement. I want it so that if the command is not "define", "add" or "remove" it throws the error. However, even if I do something like

/money define, it still throws the error. Separated, it would look like this:

if (command !== "define") throw "ERROR 1";
if (command !== "add") throw "ERROR 2";
if (command !== "remove") throw "ERROR 3";

Full code:

mp.events.addCommand('dinheiro', (player, _, command, amount, targetPlayer) => {
    var isSuccess = true;
    try {
        if (command !== "definir" || (command !== "adicionar") || (command !== "retirar")) throw "ERORR 1";
    }
    catch (err) {
        isSuccess = false;
    }
    if (isSuccess) {
      //code
    }

I removed unnecessary parts, but I always get throw the ERROR 1, so the problem is most probably in the if statement.

Hugo Almeida
  • 105
  • 7

1 Answers1

2

if (command !== "define" && (command !== "add") && (command !== "remove")) throw "ERROR 1";

The or operator (||) will return true as soon as one of the operands evaluates to true so e.g. if the command is "add" the first clause is true because command is not "define".

Stefan Bajić
  • 374
  • 4
  • 14