我目前正在尝试完成我的大学课程,但我很难让我的代码工作。有人可以帮助我吗?
现在更新你的程序,以便检查彩票的工作 结果由一个名为checkNumbers()的函数完成。这个功能 应该将客户编号和中奖号码列为 参数。客户编号应从函数返回 叫做getCustomerNumber()。中奖号码应该是 从一个名为getWinningNumbers()的函数返回。显示 结果应该由一个名为displayResult()的函数完成。该 整个过程应该由一个名为init()的函数启动。
<!doctype html>
<html lang="en">
<head>
<script type="text/javascript" src="lottotask5.js">
</script>
<meta charset="utf-8">
<title>DCSIS JavaScript Module TMA</title>
</head>
<body>
</body>
</html>
function init() {
new checkNumbers();
new displayResult();
new getWinningNumbers();
new getCustomerNumbers();
}
function getWinningNumbers(){
var winningNumbers = [12,17,24,37,38,43];
return winningNumbers;
}
function getCustomerNumbers(){
var customerNumbers = 12;
return customerNumbers;
}
function checkNumbers(customerNumbers, winningNumbers){
match == false;
for ( var i = 0; i < this.winningNumbers.length; i++){
if (this.customerNumbers == this.winningNumbers[i]){
match == true;
}
}
return match;
}
function displayResult(){
if(match == true){
alert("This Week's Winning Numbers are:\n\n" + winningNumbers[0]
+", "+ winningNumbers[1] +", "+
winningNumbers[2] +", "+ winningNumbers[3] +", "+
winningNumbers[4] +", "+ winningNumbers[5] +
"\n\n The Customer's Number is:\n\n" + customerNumbers + "\n\n
We have a match and a winner!");
}
else
{
alert("This Week's Winning Numbers are:\n\n" + winningNumbers[0]
+", "+ winningNumbers[1] +", "+
winningNumbers[2] +", "+ winningNumbers[3] +", "+
winningNumbers[4] +", "+ winningNumbers[5] +
"\n\n The Customer's Number is:\n\n" + 13 + "\n\n Sorry you are
not a winner this week.");
}
}
答案 0 :(得分:0)
函数displayResults无法看到数组winsNumbers的成员。您必须从displayResult()调用函数getWinningNumbers()以获取中奖号码列表。客户编号和非全局变量也是如此。