Issue with confirm & prompt


Hey guys,

my code works well so far and I get no errors etc. But what worries me is that the confirm and the two prompts appear directly after each other and only after I entered all of them the story unfolds.
Does anyone know how to fix this?

confirm("I am ready to play!")
var age = prompt("How old are you?")
if (age < 13)
    console.log("Alright then, but I won't be responsible for any damage to your little soul!")
    console.log("Go ahead and 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!")
    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 the game on a scale from 1 to 10.")
if (feedback > 8)
    console.log("Thank you! We should race at the next concert!")
    console.log("I'll keep practicing coding and racing.")


Probably something to do with codecademy. On one hand console.log and prompt/confirm are rather different and wouldn't really be used together, on the other that's pretty much the input/output codecademy presents you so it'd be nice if it carried out in the right order. You could use alerts instead of logging. You could also create a html file and run it locally


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <script src="mycode.js"></script>


var name = prompt('Who are you?');
console.log('hello ' + name);

That html includes the code file with the script tag. The js can also be put directly inside the script tag if you prefer.

You'd open index.html with your browser to execute this. You'd need to open its console to see the output.


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