I don't understand why my code doesn't work and what code does work!


#1

https://www.codecademy.com/courses/javascript-beginner-en-x9DnD/0/5?curriculum_id=506324b3a7dffd00020bf661#

i don't understand why the following code doesn't work!!

var userAnswer=prompt('Do you want to race Beiber on stage?');
if(userAnswer=='yes') {
    console.log('let continue');
    }
else  {
 console.log("Sorry you can't carry on the game!" );  
}

#2

Is there an error message? What is the output? Your code looks fine to me.


#3

Okay, I found it:

You used double quotes "" and single quotes '' you have to use one or the other.


#4

it says'Oops, try again. Did you remember to put in the 'yes' answer option?' after i changed

var userAnswer=prompt('Do you want to race Beiber on stage?');
if(userAnswer=='yes') {
    console.log('let continue');
    }
else  {
 console.log("Sorry you can't carry on the game!" ); 
}

to

 confirm('I am ready to play!');// Check if the user is ready to play!

var age = prompt('What is your age?');
if(age<13) {
    console.log('You are allowed to play but i take no responsibility');
}
else {
    console.log('You are allowed to play!');
 }
 console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");
console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'");
var userAnswer=prompt('Do you want to race Beiber on stage?');
if(userAnswer=='yes') {
    console.log('let continue');
    }
else  {
 console.log("Sorry you cant carry on the game!" );  
}

#5

You're being inconsistent with your quotes.

Either use only single quotes, or only double quotes.
Although, there are times when you can use both:

console.log("Hello my name is 'something'");

However, in this case, the single quotes were part of the console.log statement.

I hope this helps.


#6

now my code is

if(userAnswer==='yes') {
    console.log("let continue");
    }
else  {
 console.log("Sorry you cant carry on the game!" );  
}

and it is still returning

Oops, try again. Did you remember to put in the 'yes' answer option?

#7

You should print out exactly what exercise wants you to print out.


#8

i did but it doesn't work and i don't know how to...


#9

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