Asks prompts first then shows console logs/text


#1


Code your own adventure!

If I try to play this game, it asks me all my prompts and confirms first, and only after I've answered them I get shown the story and the rest. This means that before I've even played the story it asks me to rate it. I don't think this was how it was meant so I'm wondering how to fix it.


// Check if the user is ready to play!
confirm("I am ready to play!");
var age = prompt("What's your age?");
if (age < 13)
{ console.log("You are allowed to play, but no responsibility will be taken by x inc");
}
else 
{ console.log("Enjoy!");
};
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?'");
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.'");
};
feedback = prompt("Please rate my game 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

Seems to be working perfectly fine here!


#3

it is what it should be.because after wining the game its asking you to rate it.because there is nothing before it.

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.'");
}; //here your game end

now what do you expect?????if you want something more then simply add it :slight_smile:
i hope you've understand :slight_smile:


#4

Same thing is happening to me, it seems like it might be an issue with Chrome - all of the page dialogue boxes appear at once, without anything appearing on the results screen until after you answer the last dialogue box.

Try it on Firefox, fixed it for me... Although it still doesn't look great. I'd like to know how to get the text to appear on the screen more slowly, rather than immediately in rapid succession.

Hope this helps!


#5

I think it's your curly braces. Don't put it behind your console.log's. Instead, put it right after your if and elses. The last 3 are fine though


#8

Hello!

I was just having the same problem, and realized that this is actually a common problem!

Apparently this is a browser issue, and most people posting the questions were on Macs using Safari or Chrome. If you are on a PC OR if you download Firefox and try it on there, your code will work properly there. The prompts will run in the proper order with your story.

Here's just one of the old forum Qs I stumbled upon while researching, that was helpful:
https://www.codecademy.com/forum_questions/51c07e959c4e9d8fc200f46d


#9

I actually think it's better to use confirm for all the spots where the instructions tell you to use console.log for this one. Then you just play the short game in pop-up boxes. Seems to work better than using the console in this situation.


#10

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