我正在尝试编写一个彩票游戏,其中在 3 个单独的文本框中输入的数字 3、5、8 将产生一个成功警报框,否则一个失败警报框也会显示输入的错误数字。
我已将代码放在这里,但我不知道为什么它不起作用!
演示:http: //jsfiddle.net/9MsCY/4/
//correct numbers
var a1 = 3;
var a2 = 5;
var a3 = 8;
function mainGame(num1, num2, num3) {
var num1 = document.getElementById("a").value;
var num2 = document.getElementById("b").value;
var num3 = document.getElementById("c").value;
var a = num1;
var b = num2;
var c = num3;
if (isUnique(a,b,c)) {
if (checkGuess(a,b,c)) {
alert("Congratulations! You got all 3 numbers correct, you've won £1000!");
} else {
alert("Better luck next time. Your numbers are "+a+" , "+b+" , "+c"");
}
}
}
//function in while loop to check for unique numbers and for not null
function isUnique() {
var len = arguments.length;
for (var i = 1; i < len; i++) {
if (arguments[i] == null || arguments[i] = arguments[i-1]) {
return false;
}
}
return true;
}
//compare inputs with correct numbers
function checkGuess () {
if (a == 3 && b == 5 && c == 8) {
return true;
}
return false;
}
有人可以指出我正确的方向吗?