What is wrong with this code


#1


what if choice1 is paper


i have a syntax problem. I'm on the bottom section and i have no idea whats wrong.


Replace this line with your code. 
	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 wins";
        }
       } else {
            return "paper wins"
        };
} else if (choice1 === "paper") {
    if (choice2 === "rock") {
        return "paper wins";
        }
        } else {
            return "scissors wins"
        };
    
};


#2

Go back to the instructions and look at the hint for how to format an if/else statement inside of an else if statement. There is an extra bracket and an unnecessary semicolon in this else if. The same errors are repeated in the following else if statement. Once you make the else if statement corrections, don't forget to close the function.


#3

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";}
        }else if (choice1 === "paper") {
              if (choice2 === "rock") {return "paper wins";} 
              else {return "scissors wins";}   
      }else{
              if(choice2 === "rock"){return "rock wins";}
              else{return "scissors wins";}
      } //end if 

} //end of function

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.