dimanche 9 août 2015

best way for check one variable to different numbers in JavaScript if statements

i want check if random variable is equal to some numbers do something

for example i have 16 number that i want check them is equal to random number or not

var randomNum = Math.floor(Math.random() * (192 - 1+ 1) + 1)
if (randomNum == 1 ||  randomNum == 24 ||  randomNum == 25 ||  randomNum == 48 ||  randomNum == 49 ||  randomNum == 72 ||  randomNum == 73  ||  randomNum == 96 ||  randomNum == 97 ||  randomNum == 120 ||  randomNum == 121 ||  randomNum == 144 ||  randomNum == 145 ||  randomNum == 168 ||  randomNum == 169 )
{
    blnRand=true;
}
else
{
    blnRand=false;
}

It's very bad way for check my variable I wanna a short code like this:

if (randomNum == 1,24,25,48,49,72,73,96,97,120,121,144,145,168,169)
   blnRand=true;
else
   blnRand=false;

but don't work too, how can write short code for the if statement in here

Aucun commentaire:

Enregistrer un commentaire