Magic 8 Ball project keeps showing same result

I’m working on the Javascript magic 8 ball project Magic 8 ball

It keeps choosing the same if else the number 1 “it is decidedly so” and I really can’t figure out what I’m getting wrong.

let userName = 'Nicole';

userName ? console.log(`Hello, ${userName}`) : console.log(`Hello!`);

let userQuestion = 'Is it snowing';

console.log(`${userName} asked ${userQuestion}?`);

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

let eightBall = '';

if (randomNumber = 0) {
  eightBall = 'It is certain';
}
else if (randomNumber = 1) {
  eightBall = 'It is decidedly so';
}
else if (randomNumber = 2) {
  eightBall = 'Reply hazy try again';
}
else if (randomNumber = 3) {
  eightBall = 'Cannot predict now';
}
else if (randomNumber = 4) {
  eightBall = 'Do not count on it';
}
else if (randomNumber = 5) {
  eightBall = 'My sources say no';
}
else if (randomNumber = 6) {
  eightBall = 'Outlook not so good';
}
else if (randomNumber = 7) {
  eightBall = 'Signs point to yes';
}

console.log(`The eight ball answered: ${eightBall}`)

Hi,

This is one of those situations I really feel should throw an error but it doesn’t.

In js, conditional syntax to check for identical elements is if (a === b) or if context includes some different types, you could potentially write if (a == b) (but avoid doing this last version if in doubt).

The single equal sign actually does not throw an error, it just acts to set the value… Which is very much not what you would want here.

I completely forgot about that! Thank you so much that was driving me crazy. I guess it’s not really a syntax error. Thanks again

1 Like