This is the second time this has happened to me, where I try to use if statements to detect values from Math.random(). Instead of reading it as an If statement, it sets a to 1? I know it was poorly explained, but it was a bit hard to put together. Here is the code that messes up:
function random() { //A button calls this function
a = Math.floor(Math.random() * 15) //It sets "a" to a random value between 1 and 15
console.log(a) //I used this to check when it goes wrong
if (a = 1) {//right here, it set "a" to 1! this is what I don't understand.
b = Math.floor(Math.random())
}
How do I fix it from setting a to 1?
Aucun commentaire:
Enregistrer un commentaire