Fill out All the Prompts Before You See the Story?


#1

Ok, so not getting any error messages when running my code. Ont he surface everything checks out.

My issue is that when I run this code it prompts the user for all the variables up front, and then it runs the console logs to produce the story.

Maybe I am misunderstanding but it seems it should ask for the age, then proceed to:

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?");

At which point you say "yes" or "no" and then it displays the final portion of the story.

Yet when I run my code all I get is the age prompt, followed by the "Do you race him" prompt, and THEN it actually produces the story.

What am I missing?

// Check if the user is ready to play!
confirm("Let's do this!")
var age = prompt("What's your age?");
if(age < 13) 
{
    console.log("Go for it, but do so at your own risk...")
} 
else 
{
    console.log("Abandon all hope, all ye who enter here, but have fun!")
}
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.'")
}


#2

The console.log calls happen between the prompts (or it wouldn't reach the next prompt) but the output is held back somewhere

You can run it locally if you want:

This goes into a file named index.html and then open it with your browser (open your browser's console for output)

<!doctype html>
<body>
    <script>
// Check if the user is ready to play!
confirm("Let's do this!")
var age = prompt("What's your age?");
if(age < 13)
{
    console.log("Go for it, but do so at your own risk...")
}
else
{
    console.log("Abandon all hope, all ye who enter here, but have fun!")
}
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.'")
}
    </script>
</body>

#3

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