JavaScript控制台输出问题

时间:2018-01-26 19:53:37

标签: javascript

我试图在JavaScript中创建一个非常基本的“创建自己的冒险”,但无法获得我想要的输出。

我的代码:

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.")
}

代码在我运行时有效,但问题在于输出。当我输入1作为粥问题时,在提示时,它会停止代码并且不会说“它太热了!结束”。 是否有一些我需要添加的内容将显示“它太热了!THE END”或浏览器中的任何console.log()输出?

编辑:我期待它像使用提示一样弹出。 谢谢那些告诉我有关警报的人!它很棒!

1 个答案:

答案 0 :(得分:2)

确实有效。你在看控制台吗?如果您希望使用promptconfirm等弹出广告,请使用alert代替console.log