dimanche 13 septembre 2020

Multiple operatores in one if statement

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.

Aucun commentaire:

Enregistrer un commentaire