vendredi 29 mars 2019

In an if/else if statement, the variable is being locked into the first option. How can I fix this?

This is my general code (in JavaScript):

let x = Math.floor(Math.random()×6)+1);

if (x=1){do this} else if (x=2){do that} else if.... and so on. 

Whenever I test this code in a browser, only actions that could happen in the {do this} section happen. x is being locked as 1, even though it is meant to be a fair 6 sided die. Any ideas why this is happening, and how I can fix it?

Aucun commentaire:

Enregistrer un commentaire