Https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/learn-javascript-control-flow/projects/magic-eight-ball-1

let userName = "Moustaph Diakite"

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

let userQuestion = "What is my name?"

console.log(userName + " asked : " + userQuestion);

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

console.log(randomNumber);


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 againn"
} 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 {
    eightBall = "Signs point to yes"
}

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

// Please could you tell me why this code is only generating " It is decidedly so"

You have to use a comparison operator in your if statements. === is not the same as =

Hi there, and welcome to the forum!

You’ll notice that I’ve correctly formatted your code - the forum uses Markdown to control things like bold and italic typeface, so your attempt at indentation using those characters as a spacer didn’t quite work. :slight_smile:

You can see how I changed your post to preserve the formatting by going back to edit it, or there’s a thread on the subject here. :slight_smile:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.