vendredi 18 décembre 2015

JavaScript: Is it impossible to extend a single `ternary` operation to more than one layer?

In the following example, I've used a ternary operation instead of repeating else if s. And the code fails to run. I wonder what exactly is wrong with this snippet of code.


var ran = 1 + Math.floor(Math.random() * 100);

(ran <= 25) ?
     ran = 1;
    : (ran <= 50) ?
         ran = 2;
        : (ran <= 75) ?
             ran = 3;
            : ran = 4;

alert(ran);

Aucun commentaire:

Enregistrer un commentaire