简体   繁体   English

JavaScript控制台输出问题

[英]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. 我试图用JavaScript做一个非常基本的“创建自己的冒险”,但是无法获得我想要的输出。

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". 当我为粥问题输入1时,出现提示时,它将停止代码并且不显示“太热了!结束”。 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? 我是否需要添加一些内容,使其显示“太热了!结束”或浏览器中的任何console.log()输出?

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 . 如果您希望看到类似promptconfirm的弹出prompt ,请使用alert而不是console.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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