You must select a tag to post in this category. Please find the tag relating to the section of the course you are on E.g. loops, learn-compatibility
When you ask a question, don’t forget to include a link to the exercise or project you’re dealing with!
If you want to have the best chances of getting a useful answer quickly, make sure you follow our guidelines about how to ask a good question. That way you’ll be helping everyone – helping people to answer your question and helping others who are stuck to find the question and answer!
https://www.codecademy.com/courses/introduction-to-javascript/projects/magic-eight-ball-1
I am stuck. It keeps giving the answer for only random number =1. I can’t find the bug
…
//Magic 8 ball program.
let userName = ‘Chuck’;
userName ? console.log(Hello ${userName}!
) : console.log(‘Hello!’);
const userQuestion = ‘What is my fortune?’ ;
console.log(${userName} asks ${userQuestion}
);
let randomNumber = Math.floor(Math.random() * 8);
console.log(Random number is ${randomNumber}
);
let eightBall = ‘’;
if (randomNumber = 0) {
eightBall = ‘It is certain’;
console.log(Magic 8 ball says ${eightBall}
);
} else if (randomNumber = 1) {
eightBall = ‘It is decidedly so’;
console.log(Magic 8 ball says ${eightBall}
);
} else if (randomNumber = 2) {
eightBall = ‘Reply hazy try again’
console.log(Magic 8 ball says ${eightBall}
)
} else if (randomNumber = 3) {
eightBall = ‘Cannot predict right now’
console.log(Magic 8 ball says ${eightBall}
)
} else if (ransomNumber = 4) {
eightBall = ‘Do not count on it’
console.log(Magic 8 ball says ${eightBall}
)
} else if (randomNumber = 5) {
eightBall = ‘My sources say no’
console.log(Magic 8 ball says ${eightBall}
)
} else if (randomNumber = 6) {
eightBall = ‘Outlook not so good’
console.log(Magic 8 ball says ${eightBall}
)
} else if (randomNumber = 7) {
eightBall = ‘Signs point to yes’
console.log(Magic 8 ball says ${eightBall}
)
}
…
Console
Hello Chuck!
Chuck asks What is my fortune?
Random number is 6
Magic 8 ball says It is decidedly so
// Number is 6 but this isn’t right for number 6. It should be ‘Outlook not so good’. I can’t find the bug. The video tutorial did it with a switch. I thought if…else if should work also. It is how I started out. 'It is decidedly so is the output for randomNumber = 1.