Code runs all prompts before printing console.log


#1



I've passed the "Code your own adventure" exercises, but when I run the code on the final lesson, it seems to run through all of the confirm and prompt lines before it prints anything in the console. I'm not getting any error messages, but it seems like the code should behave differently. Can someone point me to a forum or help me figure out what I'm missing?

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


// Check if the user is ready to play!
confirm("Ready to play? Click 'ok.'");
var age = prompt("What is your age?");
if(age < 13)
{
    console.log("Dear player, you are welcome to play, but due to your age I cannot take any responsibility.");
}
else 
{
    console.log("Play on, dear player!");
}
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? Type 'Yes' or 'No'");
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.'");
}
var feedback = prompt("Please rate this game on a scale of 1 (lame...) to 10 (brilliant!).");
if (feedback > 8)
{
    console.log("Thank you! We should race at the next concert!");
}
else
{
    console.log("I'll keep practicing coding and racing.");
}


#2

My code does the exact same thing. For whatever reason, prompts take precedence over the if/else coding. Also, when I run it through safari, the answers in the console follow the flow of the code. When I run it through chrome, the answers appear out of order. I'm guessing there's a bug somewhere?


#3

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