我只是想制作这个简单的脚本来询问用户他们想要订购什么,但该功能正在被完全跳过。
var foodOrder = function (food) {
var ask = prompt("What food would you like to order?");
alert("Okay, "+ask+" coming right up.");
};
var more = prompt("Would you like anything else?");
if (more === "Yes") {
foodOrder();
}
else
{
alert("Goodbye");
}
有人看到我做错了吗?
答案 0 :(得分:5)
我认为您输入的是'yes'
而不是'Yes'
,这就是条件为false
的原因。
与此相比:
if (more.toLowerCase() === 'yes') { /* ... */ }
答案 1 :(得分:0)
试试这个 -
var foodOrder = function (food)
{
var ask = prompt("What food would you like to order?");
alert("Okay, "+ask+" coming right up.");
};
var more = prompt("Would you like anything else?");
if (more.toLowerCase() === "yes")
{
foodOrder();
}
else
{
alert("Goodbye");
}