几天来,我一直试图让这些代码在条件语句的Javascript中正常工作。我只是迷路了,不能让它正常工作。它需要满足以下条件,使用提示符从用户获取输入
如果用户试图获取饮料而不将杯子放在托盘上,则显示“请将杯子放在托盘上”。如果是自定义可填充杯,则显示“自定义可填充杯:请选择”。如果是自定义不可再灌装杯,则显示“
。
它问:你把杯子放在托盘上了吗?如果我说:是的,上面写着请选择。如果我说不:上面写着请把杯子放在托盘上。然后,它问:你有回收杯吗?如果我说:是的,它说是定制的回收杯,选择关闭如果我说:不,它问你有无续杯?如果我说:是的,它问:它是第一次使用吗?如果我说不,它会说请留下零重覆,关闭,如果我说是,它说一续,请选择,如果我说不,它说不,它说无效的杯子,请不要关闭。
我现在遇到的问题是,当你对续杯说不,然后对不续杯说不,它需要说错杯子,请离开;另一个问题是,当你对续杯说是时,它会显示正确的信息,当你点击if时,请做出选择,它不会关闭,它会继续,并询问你是否有无续杯。
到目前为止我的代码是:
let thecup = window.prompt("Did you place the cup on the tray?", "");
if (thecup === "yes") {
alert("Please choose your cup");
}
else {
alert("Please put cup on the tray");
}
//If it is the custom refillable cup, display “Custom Refillable cup: Please make your selection.”
let refillcup = window.prompt("Do you have a refillcup?");
if (refillcup === "yes") {
alert("please make your selection")
}
else {
window.prompt("Do you have a Non-Refill?", "");
}
let nonrefillcup = window.prompt("is it first time use?");
if (nonrefillcup === "yes") {
alert("one refill remaining");
}
else {
alert("Zero remaining refills");
}这是正确的代码
alert("Please put cup on the tray.")
let theCup = window.prompt("Did you place the cup on the tray? (type yes or no.)");
if (theCup === 'yes') {
alert("Please choose your cup.")
}
let yourCup = window.prompt("Do you have a Refill cup or a NonRefill cup?");
if (yourCup === 'yes') {
alert("Please choose your cup");
let refillCup = window.prompt("Do you have a refill cup? (Answer must be yes or no.)");
if (refillCup === 'yes') {
alert("please make your selection");
} else {
let firstUse = window.prompt("Is it the first time use? (Answer must be yes or no.)");
if (firstUse === 'yes') {
alert("one refill remaining");
} else {
alert("You have zero refills remaining. Please leave.")
}
}
} else {
alert("Wrong Cup. Please leave.")
}发布于 2022-02-21 01:50:20
如果我正确理解了这个问题,我认为这是一个可能的解决办法:
alert("Please put cup on the tray.")
let theCup = window.prompt("Did you place the cup on the tray? (Answer must be yes.)");
if (theCup === 'yes') {
alert("Please choose your cup.")
let refillCup = window.prompt("Do you have a refill cup? (Answer must be yes or no.)");
if (refillCup === 'yes') {
alert("please make your selection");
} else {
let firstUse = window.prompt("Is it the first time use? (Answer must be yes or no.)");
if (firstUse === 'yes') {
alert("one refill remaining");
} else {
alert("You have zero refills remaining. Please leave.")
}
}
} else {
alert("Your cup must be on the tray. Please leave.")
}https://stackoverflow.com/questions/71200098
复制相似问题