类型错误toLowercase不是一个函数

时间:2018-03-21 18:17:34

标签: javascript string function

我开始学习javascript。我有一个任务,我必须在计算机上创建一个简单的摇滚,剪刀游戏。

该程序最终会促使人类在转弯时输入摇滚,纸张或剪刀。为了确保数据验证,程序必须对人类输入的任何字母进行资本化。

为此,我尝试使用toLowercase函数,可以在下面的第二行代码中看到。

作为回报,我在控制台中收到以下内容:

TypeError:playerSelection.toLowercase不是函数

function playRound(playerSelection, computerSelection) {


    playerSelection = playerSelection.toLowercase();
    var resultMessage = "";

    if (playerSelection == "rock" && computerSelection == "paper") {
        resultMessage = "You Lose. Paper beats Rock"; 
    }

    else if (playerSelection == "rock" && computerSelection == "scissors") {
        resultMessage = "You Win. Rock beats Scissors"; 
    }

    else if (playerSelection == "paper" && computerSelection == "scissors") {
        resultMessage = "You Lose. Scissors beats Paper"; 
    }

    else if (playerSelection == "paper" && computerSelection == "rock") {
        resultMessage = "You Win. Paper beats Rock"; 
    }

    else if (playerSelection == "scissors" && computerSelection == "paper") {
        resultMessage = "You Win. Scissors beats Paper"; 
    }

    else if (playerSelection == "scissors" && computerSelection == "rock") {
        resultMessage = "You Win. Scissors beats Rock"; 
    }

    else {
        resultMessage = "Draw";
    }

    return resultMessage;

}

console.log(playRound("rock",compPlay));

1 个答案:

答案 0 :(得分:4)

不是,toLowerCase()是。 (不是案例,更多是Camel case)。