Why does = always give the same response in my code block? (from the magic eight ball project)

https://www.codecademy.com/paths/front-end-engineer-career-path/tracks/fecp-22-javascript-syntax-part-i/modules/wdcp-22-learn-javascript-syntax-conditionals/projects/magic-eight-ball-1

Whenever I run the codeblock below, the output is always ‘Boo!’. Why?

randomNumber = Math.floor(Math.random() * 8);

var eightBall = ‘’;

if(randomNumber = 1) {eightBall = ‘Boo!’}

else {eightBall = ‘try again’}

console.log(${eightBall});

Because you are using the assignment operator not the equality one

Assignment

let a = 5;

Equality

if (a === 5) {
  \\ do this
}
1 Like

Thanks for your help.
Should I change the assignment operator to the equality operator on the first line (randomNumber = Math.floor…) ?
In this case, if I use the assignment operator inside the conditional operator if, does that automatically update randomNumber to always be 1?

No, you want that to be assigning a random num to the variable

Yes