vendredi 4 décembre 2020

Is there a random function in javascript that doesn't take the range of two numbers?

I want the computer to randomly choose either 8 or 2. I tried doing (Math.random()*8)+2, it chooses a random number BETWEEN 8 and 2 but I want the computer to randomly choose 8 or 2.

So I tried a different way, and I did this:

if(b==0){
var a = 2;
}
else{
var a = 8;
}

However, it is not working. Is there a more efficient and better way?

Thank you, Paul




Aucun commentaire:

Enregistrer un commentaire