Magic 8 ball project

so I am having trouble with it printing the specific name that I type in the userName section. I want it to print Oscar if I type Oscar and Jane if I type Jane but I don’t know how to get it to do that do you think you could be of some assistance

Hi there! Could you copy and paste your code to the forum here? That would make it easier to see what is happening with your code.


ok I will thx for the tip wait one sec

let userName = ‘’;

userName ? console.log(‘Hello, Jane’) : console.log(‘Hello!’);

(not code after this)

this is all I have gotten done so far but I am stuck

I want it to print the username I type into the userName variable and not only print Jane

Also, could you paste a link to the lesson you are working on? That way we can see exactly what the lesson intends for you to do.

1 Like

Hey @grizzlyslayer, after you get unstuck here, please take a look at this article: How to ask good questions (and get good answers). It’ll help for next time.

and @abbrendle thanks for being so helpful!


Hello grizzlyslayer!
If this is all the code you have:

let userName = ‘’;
userName ? console.log(‘Hello, Jane’) : console.log(‘Hello!’);

Then I suspect the issue you are having is with the console.log('Hello, Jane') part.
Remember that in order to use the data stored in a variable, you need to use that variable name. So for your case, it would be:

let userName = ‘’;
userName ? console.log(‘Hello, ’+userName) : console.log(‘Hello!’);

And finally, if you want Oscar to print out, then you’d need to define let userName = 'Oscar';
Do you see the difference? Hope that helped!


hello thx so much for trying to help me I ended up looking how to do something and my dad helped too and my problem was fixed! thx everyone!

1 Like

Can I jump in on this thread? I completed the project doing the switch method, but I’m having trouble with the If else method…?

let userName = (‘Bec’)

userName ? console.log(Hello ${userName}) : console.log(‘Hello’);
let userQuestion = ‘Can you answer my question?’;
console.log(The user asked: ${userQuestion});

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

let eightBall = ‘’;

if(randomNumber = 0) console.log (‘It is certain’)

}else if(randomNumber = 1) console.log (‘It is decidedly so’); {

}else if(randomNumber = 2) console.log (‘Reply hazy try again’); {

}else if(randomNumber = 3) console.log (‘Cannot predict now’); {

}else if (randomNumber = 4) console.log (‘Do not count on it’); {

}else if (randomNumber = 5) console.log (‘My sources say no’); {

}else if (randomNumber = 6) console.log (‘Outlook not so good’); {

}else (randomNumber = 7) console.log (‘Signs point to yes’);

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

1 Like

Hi @rebeccaredfern, first let me share this with you, it will be useful in the future! How Do I Format Code In My Posts?

About your problem, you are using single = symbols rather than == or === (that are used for comparison!)


ah thankyou so much!


im not sure if you are doing your code right

just looked it up because I forgot too

else if(randomNumber = 1) {console.log (‘It is decidedly so’)

that is the correct code