我的函数使用增强的for循环,但不是正常的for循环

时间:2018-04-28 17:14:02

标签: javascript

这两个前两个函数返回数字和数组

function getCustomerNumber() {
    let customerNumbers = 312;

    return customerNumbers;
}



function getWinningNumbers() {
    let winningNumbers = [];
    winningNumbers.push(12,17,24,37,38,43);

    return winningNumbers;


function checkNumbers(getCustomerNumber, getWinningNumbers) {
    let match = false;
    let text;
    let winNum = getWinningNumbers;
    let cusNum = getCustomerNumber;
    let i;

    for (i = 0; i < winNum.length; i++)
        if(winNum[i] == cusNum)
            match = true;


    if(match)
        text = "\n\nWe have a match and a winner!";
    else
        text = "\n\nSorry you are not a winner this week."

    return text;
}

ny checkNumbers函数存在问题,它似乎与增强的for循环有效但不是正常的循环

1 个答案:

答案 0 :(得分:0)

您将winNum和cusNum定义为对函数的引用,而不实际调用它们:

function checkNumbers(getCustomerNumber, getWinningNumbers) {
    let match = false;
    let text;
    let winNum = getWinningNumbers();
    let cusNum = getCustomerNumber();    // <---- parentheses...
...