Issue with confirm & prompt


#1


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


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!")
}
else
{
    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!")
}
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 the game on a scale from 1 to 10.")
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

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

index.html:

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

mycode.js:

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.


#3

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