7. what if choice1 is paper?


#1


I am so confused on this section, ive tried for an hour and just gave up 
need help

Oops, try again. Your code returned 'The result is a tie!' instead of 'paper wins' when the inputs are paper and rock

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(userChoice === computerChoice) {
     return "The result is a tie!";
    }
    else if(userChoice === "rock") {
           if(computerChoice === "scissors"){
               return "rock wins";
           }
           else {
              return "paper wins";
           }
    }
    else if(userChoice === "paper") {
         if(computerChoice === "rock"){
      return "paper wins";
     }
     else{
      return "scissors wins"; 
     }
    }
};


#2

for your comparisons inside the compare function, why do you use userChoice and computerChoice?

You should use the function paramters (choice1 and choice2) instead


#3

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