Help!. stuck at rock paper game. line 7


#1


LINE 7


HELP ME! I'M STUCK. SOMETHING IS WRONG WITH MY ELSE IF=PAPER. CAN YOU TELL ME WHAT'S WRONG? PLEASE.

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


#2

you create an else if statement to see what choice1 is:

else if (condition){

}

then inside the else if, you nest an if and an else statement to check for choice2:

else if (condition){
   if (condition){

  } else {

  }
}

see how i nested the if and else inside the else if? you only nested the if inside the else if, not the else.


#3

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