JavaScript Error. 5. The story hearts up


#1

Threre is an error when i check my code. Why? it works well.
Look this video


Regards, Alexey


#2

Please paste in your code so we can help you


#3

He did, watch the video or enlarge the beginning.


#4

Its hard to debug by seeing the code via a picture or video especially in JS


#5

Would you like me to show the code and the problem?


#6

yeah go ahead  


#7


console.log("You are at a Justing 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;
userAnswer = prompt("Do you want to race Bieber on stage?");
if(userAnswer==="yes")
{
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
}
else
{
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}

When the prompt is filled in, the error is:
'Oops, try again. Did you add an if statement to your code?'


#8

The var userAnswer should have the prompt declared in the initialisation of the variable, so `var userAnswer = prompt("...");


#9

@betablaster54616 @14cowado
You are getting an error as this is not the full code (the previous lesson's code is not here)..
Please reset the lesson and then you can paste in the code for this lesson..


#10

@betablaster54616 In the future, please paste the code and not a video. You may not always get someone who is willing to do that.


#11

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 Bieber on stage?");
if (userAnswer==="yes")
{
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
}
else
{
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}


#12

i have no iead why it don't see "if"


#13

You still getting an error ?

Have you tried resetting the lesson and then pasting in your code ..
As it didn't carry over the last lesson's code thus you are getting an error..

Please paste in updated code if you still get an error after doing the above


#14

A post was split to a new topic: JavaScript Error. 5. The story hearts up


#15

Getting the same with this, Same error message too: "> Oops, try again. Did you add an if statement to your code?"

`// Check if the user is ready to play!
confirm ("yeah I confirm");

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 Bieber on stage?");
 if (userAnswer === "yes") {
    console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
 }
 else {
    console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
 }`

#16

Hi, I'm Amber--very new user (as of today); first post. I arrived at this forum because I was experiencing the same exact error as betablaster54616 and nebastion, with it seemingly not recognizing the "if" statement. (The console would "print" the correct verbiage with either condition; it just would not let me proceed past the error.)

zainabrawat's reply is what helped me...but, to clarify a little bit in case it's needed:

  1. Even after I reset and re-entered the code, I still got the error...it's because the previous lesson is wiped out. I had been copying it all to a .txt file so I could test it again later on my own and keep track...so I deleted everything in the lesson and copied IT ALL again, starting with //Check if the user is ready to play! When I submitted, it accepted and let me move forward. I think it would be helpful if the prior lesson didn't delete itself out and make us re-enter it...but maybe that's part of the lesson.

  2. I went back and tried it again (for S&G) starting with [[console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");]] just to see if it did it again...and this time it let me proceed, even without the beginning of the lesson having been re-entered. I thought that was strange but worth noting.

Entire code from my .txt file, including previous part that was wiped out (and my comment):



// Check if the user is ready to play!
confirm("I am ready to play!");
var age = prompt("What's your age?");
if(age < 13) {
console.log("OK, you can play...but we take no responsibility!");
}
else
{
console.log("Have fun!");
}

//Game starts…next lesson….

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 Bieber on stage?");
if(userAnswer === "yes") {
console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
}
else {
console.log("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");
}




Hope this helps!


#17

VERY GOOD! Ambiehead ! Your FULL code works! thank you all, guys!


#18

Thank you! So it was the cache of the previous session that was causing it?
Regardless, CHEERS!!!


#19

You are welcome, betablaster54616 and @nebastion! I don't know enough about "cache" to say yes or no to that...honestly, I just took what @zainabrawat said and re-applied the first part of the code (from the previous lesson) and combined it with the current lesson's code...after having tried it WITHOUT the previous code at least 3 times and beating my head against the wall lol....