mercredi 16 décembre 2015

JavaScript: Is it allowed to use a `ternary` statement inside an `if` statement?

In the following script, I've used a ternary statement in the else if portion of an if statement, juxtaposing the two. In a case like this, should I substitute another if statement inside the else if?

var attackOpt = prompt('Which attack option does Angelo use in this turn?');

// Remaining number of times Angelo can cast spells:
var angMP = 3;


// Validity Check to see if the attack option entered can be executed:
while (true) {

        if (attackOpt === 'slash') {
            break;
        }

        else if (attackOpt === 'magic') {
            (angMP) ?
                 break;
                : attackOpt = prompt('Angelo can no longer cast spells. Select again.');
        }

}

Aucun commentaire:

Enregistrer un commentaire