得到某种javascript错误但idk什么是错的

时间:2015-07-19 14:25:42

标签: javascript

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

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

    if(choice2 === "scissors") {
        return "rock wins";
    }
    else {
        return "paper wins";
    }

}

此代码来自codeacademy https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/2?curriculum_id=506324b3a7dffd00020bf661

2 个答案:

答案 0 :(得分:0)

检查一个正确的。

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

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

        if(choice2 === "scissors") {
            return "rock wins";
        }
        else {
            return "paper wins";
        }

    }

答案 1 :(得分:0)

您错过了功能括号{}

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

if(choice2 === "scissors") {
    return "rock wins";
}
else {
    return "paper wins";
   }
  }
};

希望这会有所帮助。