gpt4 book ai didi

javascript - 我试图在 javascript 中创建带有时间属性的东西,但它不起作用

转载 作者:行者123 更新时间:2023-12-03 12:39:54 25 4
gpt4 key购买 nike

我想做一个简单的if语句,当时间>7时它会做一些事情,当时间<16时它会做一些事情。在我检查 JShint.com 错误并修复错误后,该功能仍然无法工作,只是什么也不显示,我不知道问题是什么..

下面我写了代码

提前感谢您的帮助!

var avucado =  ["eggs ","avucado ","tommato ","mayonnaise ","pickles ","gamba"];
var eggSalad = ["eggs ","dill ","mayonnaise ","pickles"];
var tuna = ["tuna ","coriander ","pickles ","mayonnaise ","gamba"];
var cheeze = ["yellow cheeze ","mayonnaise ","tommato ","cucumber"];
var sausage =["sausage ","mustard ","mayonnaise ","tommato ","pickles"];
var choice1 = ("you chose:");
var choice2 = ("the ingredients of your sandwich are:");
var lunch = input.value;
/*jslint evil: true */
/*jshint multistr: true */

function food (){
if (time>7){
switch(lunch){
case 'avucado':
document.write(choice1 + " " + 'avucado.'+ "<br /><br />" + " " + choice2 +
" " + avucado + ".");
break;
case 'egg salad':
document.write(choice1 + " " + 'Egg salad.'+ "<br /><br />" + " " + choice2 +
" " + eggSalad + ".");
break;
case 'tuna':
document.write(choice1 + " " + 'Tuna.'+ "<br /><br />" + " " + choice2 +
" " + tuna + ".");
break;
case 'yellow cheeze':
document.write(choice1 + " " + 'Yellow cheeze.'+ "<br /><br />" + " " + choice2 +
" " + cheeze + ".");
break;
case 'sausage':
document.write(choice1 + " " + 'Sausage.'+ "<br /><br />" + " " + choice2 +
" " + sausage + ".");
break;
default:
document.write("we dont have " + lunch + " yet, but! you can send us \
mail and we will make that sandwich for you anyway!");
}else{document.write("you'll get you'r order tomorrow by 7AM");
}
}
}

最佳答案

而不是这个:

}else(time<24)

你想要这个:

}else if(time<24)
<小时/>

按照您现在的方式,您的 else 子句不是条件语句。

<小时/>

当我将你的代码放入http://www.jshint.com/时,还有其他代码问题。您确实应该检查错误控制台,因为它可能会向您显示脚本错误。无论如何,下面是代码的修正版本,它通过了 jsHint 的合法 JavaScript 检查:

var avucado = ["eggs ", "avucado ", "tommato ", "mayonnaise ", "pickles ", "gamba"];
var eggSalad = ["eggs ", "dill ", "mayonnaise ", "pickles"];
var tuna = ["tuna ", "coriander ", "pickles ", "mayonnaise ", "gamba"];
var cheeze = ["yellow cheeze ", "mayonnaise ", "tommato ", "cucumber"];
var sausage = ["sausage ", "mustard ", "mayonnaise ", "tommato ", "pickles"];
var choice1 = ("you chose:");
var choice2 = ("the ingredients of your sandwich are:");
var food = function () {

if (time < 7) {
var lunch = input.value;
switch (lunch) {
case 'avucado':
document.write(choice1 + " " + 'avucado.' + "<br /><br />" + " " + choice2 +
" " + avucado + ".");
break;
case 'egg salad':
document.write(choice1 + " " + 'Egg salad.' + "<br /><br />" + " " + choice2 +
" " + eggSalad + ".");
break;
case 'tuna':
document.write(choice1 + " " + 'Tuna.' + "<br /><br />" + " " + choice2 +
" " + tuna + ".");
break;
case 'yellow cheeze':
document.write(choice1 + " " + 'Yellow cheeze.' + "<br /><br />" + " " + choice2 +
" " + cheeze + ".");
break;
case 'sausage':
document.write(choice1 + " " + 'Sausage.' + "<br /><br />" + " " + choice2 +
" " + sausage + ".");
break;
default:
document.write("we dont have " + lunch +
" yet, but! you can send us mail and we will make that sandwich for you anyway!");
}
} else if (time < 24) {
document.write("you'll get your order tomorrow by 7AM");
}
}

关于javascript - 我试图在 javascript 中创建带有时间属性的东西,但它不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23571383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com