Javascript Module 2 EightBall - Stuck, plz help?

In the 2nd Javascript module, I input the exact same code the video tutorial did & a)I get an error, and b) the video author’s output didn’t show his name either, it just shows “Hello $userName”. My main question is a., why am I getting errors from same code as video-tutorial?

Here is URL of tutorial/project:
https://www.codecademy.com/courses/introduction-to-javascript/projects/magic-eight-ball-1

Can anyone tell me what’s wrong in this code?

let userName = 'Sean';

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

console.log('Hello!');

let userQuestion = 'Some Question?'

console.log('Ready to go?');

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

let eightBall = '';

switch (randomNumber){

case 0:

eightBall = 'It is certain';

break;

case 1:

eightBall = 'It is decidedly so';

break;

case 2:

eightBall = 'It is decidedly so';

break;

case 3:

eightBall = 'It is decidedly so';

break;

case 4:

eightBall = 'It is decidedly so';

break;

case 5:

eightBall = 'It is decidedly so';

break;

case 6:

eightBall = 'It is decidedly so';

break;

case 7:

eightBall = 'It is decidedly so';

break;

default;

}

console.log(eightBall);

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! :slight_smile:

Hello, and welcome to the community!

You might want to read this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

I suspect that you’re missing backticks `` in your first console.log.

You need them when using embedded expressions.

Hope this helps!

1 Like

Thanks for feedback, but I don’t think that’s it - when I remove everything below the randomNumber line, code runs perfectly.

It’s this part that produces errors:

let eightBall = '';

switch (randomNumber){

case 0: 

eightBall = 'It is certain';

break;

case 1:

eightBall = 'It is decidedly so';

break;

case 2:

eightBall = 'It is decidedly so';

break;

case 3:

eightBall = 'It is decidedly so';

break;

case 4:

eightBall = 'It is decidedly so';

break;

case 5:

eightBall = 'It is decidedly so';

break;

case 6:

eightBall = 'It is decidedly so';

break;

case 7:

eightBall = 'It is decidedly so';

break;

default;

}

console.log(eightBall);

Here you’re missing a semicolon at the end

Should be default:


Let me know if that works

1 Like

@dev9618012063 I have edited your posts to correctly format the code sections. Please take a look at this post as a reference on how to do this.

It makes it much easier for us to help you with errors. :slight_smile:

  default:
    eightBall = '';
    break;