Choice 1 is paper?


#1

/*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") {
       
   } else 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

we have our function, inside our function we are going to check who won. First we determine if the result is a tie. Then we are going to add 3 else if's to check what the user choice, inside each else if we check what the computer choice. So we add an else if statement:

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

}

then inside else if we are going to check for choice2, we do this using if and else:

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

    } else {

    }
}

then after this else if, we can add the next else if to check for the other options of choice1, but make sure you keep good track of the {}:

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

    } else {

    }
} // make sure to close else if of choice1
else if (choice1 === "paper"){

}

see comment in code. Please follow this structure to go through all possible options


#3

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