gpt4 book ai didi

javascript - 我的发电机不工作

转载 作者:行者123 更新时间:2023-11-28 19:33:03 25 4
gpt4 key购买 nike

嗨,我正在生成我镇上的餐馆列表(因为我和我丈夫永远无法决定其中一家),看起来生成器只在 0-7 之间进行选择(总共 39 家)。

到目前为止我还没有发现任何问题,所以我需要一双额外的眼睛。我到底做错了什么?请帮忙!

<html>
<head>

<title>Restaurant Generator</title>
<h1 style="font-family:helvetica;">Restaurant Generator</h1>
<script language type="text/javascript">
<!--

function getMessage()
{
var ar = new Array(40)
ar[0] = "Painted Horse"
ar[1] = "Indian Coffe Co"
ar[2] = "Taco Bell"
ar[3] = "Chinese by Food Pyramid"
ar[4] = "Cinese Buffet"
ar[5] = "Luigis"
ar[6] = "Dink's"
ar[7] = "La Fiesta"
ar[8] = "Taco Mayo"
ar[9] = "Papa Murphey's"
ar[10] = "Hideway"
ar[11] = "McAllister's"
ar[12] = "McDonalds"
ar[13] = "Jimmy Johns"
ar[14] = "Rolling Pin"
ar[15] = "Lot A Burger"
ar[16] = "Philips caf"
ar[17] = "OKWU caf"
ar[18] = "Chilli's"
ar[19] = "Bouldevard Dinner"
ar[20] = "Frank and Lola's"
ar[21] = "Garfields's"
ar[22] = "Subway"
ar[23] = "Sonic"
ar[24] = "Golden Corral"
ar[25] = "Buffalo Wild Wings"
ar[26] = "Sushi One"
ar[27] = "Eskimo Joe's"
ar[28] = "Eggbert's"
ar[29] = "Midway Caffee"
ar[30] = "Copper Bar"
ar[31] = "Billy Sims"
ar[32] = "Arby's"
ar[33] = "KFC"
ar[34] = "Hunan's"
ar[35] = "Braum's"
ar[36] = "A&W"
ar[37] = "Burger King"
ar[38] = "Guess again"
ar[39] = "Wallmart hot food"
// add as many more that you can stand but make
// sure you update the value '7' in the alert box
var now = new Date()
var sec = now.getSeconds()
alert("Today you are eating at:\n\n" + ar[sec % 7])
}

//-->
</script>

</head>
<!-- <body onLoad="getMessage()"> this will automatically generate when you load the page-->
<body>
<form>
<input type="button" style="height:100px; width: 600px; font-size:50px" name="again" value="Click Me" onClick="getMessage()">
</form>

</body>
</html>

最佳答案

ar[sec % 7]更改为ar[sec % ar.length]。 (“确保更新警报框中的值“7””应该是一个致命的赠品 - 40 可以代替 7,但是 ar. length 使得不需要更新,因为它适用于任意数量的餐厅。)

顺便说一句,不是错误,但非常不JavaScripty:创建数组的方式。它应该按原样工作,但是很容易出错。我建议改变

var ar = new Array(40)
ar[0] = "Painted Horse"
ar[1] = "Indian Coffee Co"
//...

进入

var ar = [
"Painted Horse",
"Indian Coffee Co",
//...
];

关于javascript - 我的发电机不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26394520/

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