jeudi 23 juillet 2020

(Javascript) My if statement is acting like the conditions are true every time I run the code [closed]

let x = (Math.floor(Math.random() * 6 + 1))
console.log(x)

if (x = 6)
console.log('that was a 1/6 chance')

The code is intended to print "that was a 1/6 chance" whenever I run the program and x (the variable storing the random number) is 6. My actual result is the code saying "that was a 1/6 chance" whenever the code runs, which is technically true, but not my intended result.

Aucun commentaire:

Enregistrer un commentaire