程序有效,但Code Academy不承认它是正确的

时间:2015-09-12 01:08:24

标签: javascript

这是我的代码:

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice <= 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer:" + " " + computerChoice);

var compare = function(choice1, choice2){
if (choice1 === choice2) {
    return "The result is a tie!";
}

else if (choice1 === "rock") {

    if(choice2 === "scissors") {
        return "Rock smashes the fuck out of those scissors!";
    }
    else {
        return "Oh shit, that rock was not prepared for full coverage OF PAPER ";
    }
}

else if (choice1 === "paper") {

    if (choice2 === "rock"){
        return "Oh damn, that paper just covered the shit out of that rock!";
    }
    else {
        return "Those scissors cut that weak paper shit into pieces!";
    }
}

else if (choice1 === "scissors") {

    if (choice2 === "rock"){
        return "Wow! That rock smashed those scissors so hard into the ground that their grandparents felt it. And they're dead!";
    }
    else {
        return "That wimpy-ass paper was sliced into ribbons...Well, you know, if the paper was made of that ribbon material. BUT IT'S NOT.";
    }
}
} 
compare(computerChoice, userChoice);    

控制台返回正确的结果,代码有效,但CodeAcademy说这是错误的。保存并提交时,错误消息显示:

  

你的代码返回'那张懦弱的纸被切成丝带......好吧,你知道,如果纸是用那种带状材料制成的。但不是。当输入是剪刀和纸张时,而不是'undefined'

现在到底发生了什么事?

1 个答案:

答案 0 :(得分:0)

你需要像CodeAcademy所期望的那样做。使用相同的变量名称,相同的代码结构等。