简体   繁体   中英

JavaScript console output issue

I am trying to make a very basic "create your own adventure" in JavaScript and cannot get the output that I am wanting.

My Code:

 var enter = confirm("You are outside a forest cabin. Press OK to enter."); if (enter) { //go into the cabin var bowl = prompt("You see three bowls of porridge. Eat bowl 1, 2, or 3?") if (bowl == 1) { console.log("It's too hot! THE END"); } else if (bowl == 2) { console.log("It's too cold! THE END"); } else { console.log("It's delicious."); var hours = "The porridge makes you sleepy. Nap for how many hours?"; var sleep = prompt(hours); sleep = Number(sleep); if (sleep <= 2) { console.log("You wake just in time, and scamper away!"); } else { console.log("You sleep to late, and are eaten by hungry bears."); } console.log("THE END."); } } else { //didn't go in console.log("And that's the world's shortest fable. THE END.") } 

The code works when I run it however the issue is with the output. When I type in 1 for the porridge question, when prompted, it stops the code and doesn't say "It's too hot! THE END". Is there something that I need to add that will display "It's too hot! THE END" or any of the console.log() output in the browser?

EDIT: I was expecting it to POP UP like it was doing with Prompt. Thank you for those that told me about alert! It is working Great!

It does work. Are you looking at the console? If you're expecting a popup like prompt and confirm , use alert instead of console.log .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM