When I run this, it claims x is undefined on the on the line with the for loop.
Full code:
function getCustomerNumbers() {
var customerNumbers = [];
customerNumbers.push(12, 17, 24, 37, 38, 43);
return customerNumbers;
}
function getWinningNumbers() {
var winningNumbers = [];
winningNumbers.push(12, 17, 24, 37, 38, 43);
return winningNumbers;
}
function checkNumbers(x, y) {
var matches = 0;
for (i=0; i<x.length; i++) {
for (j=0; j<y.length; j++) {
if (x[i] == y[j]) {
matches++;
}
}
}
return matches;
}
function displayResult() {
checkNumbers(getWinningNumbers(), getCustomerNumbers())
alert("This Week's Winning Numbers are:\n\n" + getWinningNumbers().toString() +
"\n\nThe Customer's Number is:\n\n" + getCustomerNumbers().toString() + "\n\nNumber of Matches:" + checkNumbers());
}
function init() {
displayResult();
}
window.onload = init;
Later it runs, with arrays going into values x and y. It ran fine when it was just x as an array and one for loop.
Anyone know what is wrong here?
function checkNumbers(var x, var y)-- why do you havevarlisted in the parameters? It should befunction checkNumbers( x, y)iandj?checkNumbers