All dialogue boxes are coming together...!


#1

ALL DIALOGUE BOXES ARE COMING TOGETHER...!!

The console is logged only after the display of all dialogue boxes in the code.
But i want it to be printed one by one , as per the code.
That is to first ask " Enter your age". Then after the things in 'if/else' statement is printed. I prefer to show the next dialogue box only after this process. But its not working that way..

onfirm("Are you ready to play?");// Check if the user is ready to play!
var age = prompt("Enter Your Age");
if(age < 13 )
    {
        console.log("You are allowed to play, but i have no responsibility");
    }
else
    {
        console.log("Go on ..Lets play together");
    };
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 my game out of 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

Can you please explain it a bit better if possible. I'm not sure I can clearly understand what you want to do.
You ask user their age and after that you have if/else statement. And after that what you want to do ?


#3

They mean that all of the prompts are coming at once, and I'm having the same problem. It would ask my age and then ask if I want to race, then ask me to rate, with nothing in between. And THEN, after I answered it all, would I ever get anything on my screen about the game story.


#4

All prompts are coming at once together. After that the console is logged.
I want the code to be such that,
Ask for a prompt. Then log the console. Then ask for another prompt.


#5

I'm having the same problem. It looks like something that needs to be fixed on Codecademy's end, not anything that anyone is doing wrong with their code.

If the code were run outside of Codecademy's sandbox, it would work perfectly. The messages are being printed to the console at the right times relative to the prompts -- it's just that in the Codecademy view the console isn't getting refreshed until the script is complete.

I tested this theory by embedding the Javascript in a regular HTML page, like so:

<!DOCTYPE html>
<!-- trying to make a piece of codecademy Javascript work right -->
<html>
<head>
<script>
<!-- hide script from old browsers
// Check if the user is ready to play!
var ans = confirm("Would you like to play an adventure game?")
var age = prompt("What is your age?")
if (age < 13) {
    console.log("You can play, but I won't be responsible for untoward consequences!")
}
else {
    console.log("Okay, you're old enough -- let's go!")
}
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.substring(0,1)==="y") {
    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 to 10 -- 10 being highest")
if (feedback>8) {
    console.log("Thank you! We should race at the next concert!")
}
else {
    console.log("I'll keep practicing coding and racing.")
}
// end hiding script from old browsers -->
</script>
</head>
<body>This is the regular page text.  Open Developer Tools > Console Window (that's where it is in Google Chrome, anyway) to see where the story line will be printed by Javascript, then refresh this page.</body></html>

#6

Here is my old code. It works, and it gives you alerts 1 by 1 how you progress.

confirm("Are you ready to play?");
var age = prompt("How old are you?");

if (age<13) {
    alert("You're younger then 13 so you can play but on your own responsibility!");
} else {
    alert("Welcome to my virtual world. Enjoy your stay! :)");
}

alert("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");

alert("Suddenly, Bieber stops and says, 'Who wants to race me?'");
userAnswer = prompt("Do you want to race Bieber on stage?");

if (userAnswer === "yes"){
    alert("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
} else {
    alert("Oh no! Bieber shakes his head and sings 'I set a pace, so I can race without pacing.");
}

feedback = prompt("Please rate this game on the scale from 1-10.");

if(feedback > 8) {
    alert("Thank you! We should race at the next concert!");
} else {
    alert("I'll keep practicing coding and racing.")
}

#7

What browser are you using? For me on the latest Google Chrome on Windows 7, the code you quoted doesn't print anything at all to Codecademy's embedded simulated console window, until after the final "Please rate this game" question has been answered.

Yes, the code is perfectly valid -- as was amalnathsathyan's original code, more or less -- and if it's embedded in a regular HTML page it works just fine on Google Chrome or anywhere else, as I described.

The question is, why does the embedded Codecademy console window get updated after every Javascript command for some people, but others are seeing a delayed update until the script is completely finished with its run?


#8

P.S. I see how using alert() very nicely avoids the problem with the console not refreshing, but it doesn't seem to match the instructions as they're given -- e.g.,

So it seems as if either the instructions, or the embedded Codecademy Javascript console, should be patched somehow.


#9

The code passes the text with alerting the sentences. It might be problem from codeacademy, browser, system you are on. Anything can have hands on why this is not working like it should but it needs testing to get a true answer.
Anyway, for me it is better that you talk with alerted messages as they come nicely one after another. It passes the test, which is important. Even in a real world of programming you won't be using prompt and then consol.loging text. This is just an exercise which helps you understand things and it doesn't matter if you used console.log or alert as long as the rest of the code is valuable and working.
For bug in mind maybe, it would be good so this get tested ( if needed ).
Admins you say, if you see this message !


"alert" workaround not accepted for all Chrome console messages appearing at the end
#10

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