【发布时间】:2015-06-16 01:05:00
【问题描述】:
我有一个问题要解决,我必须使用循环遍历每个位置 一组“中奖号码”,用于检查可变客户编号(从键盘输入)是否与任何中奖号码匹配。 我必须使用 For 循环遍历中奖号码数组中的每个位置,并将客户号码与数组包含的每个号码进行比较。 我不能使用任何方法来解决这个问题 谢谢你的帮助! 这是我到目前为止所做的:
var customerNumbers = prompt("Enter your number:");
var winningNumbers = [12, 17, 24, 37, 38, 43];
for (var i = 0; i < winningNumbers.length; i++) {
if (customerNumbers == 12 || //condition determinates the winning numbers
customerNumbers == 17 ||
customerNumbers == 24 ||
customerNumbers == 37 ||
customerNumbers == 38 ||
customerNumbers == 43)
alert("This week Winning numbers are:" + "\n" + "\n" + winningNumbers + "\n" + "\n" + "The customer's Number is:" + "\n" + "\n" + customerNumbers + "\n" + "\n" + "We have a match and a winner!");
} else {
alert("This week Winning numbers are:" + "\n" + "\n" + winningNumbers + "\n" + "\n" + "The customer's Number is:" + "\n" + "\n" + customerNumbers + "\n" + "\n" + "Sorry you are not a winner this week");
}
【问题讨论】:
-
那么问题出在哪里?上面的代码不起作用?
-
你对 for 循环了解多少?你试过什么?您尝试过的解决方案有什么问题?
-
“我无法使用任何方法来解决这个问题”是什么意思?这是某种家庭作业,否则这是一种愚蠢的约束?
标签: javascript arrays loops