I dont know what's wrong (8/9)


#1


I keep getting this "Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and rock". Please help :sweat:


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


#2

i am confused by your code. Let me explain, what you are trying to do in these exercises (exercise 6,7 and 8) is make 3 three else if statements to check what choice1 is:

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

then inside each else if statement you nest a if and else to check for choice2:

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

be careful to close the else if before moving on to the next else if:

else if (choice1 == "rock"){
  if(choice2 === "scissors") {
    return "rock wins";
  } else {
     return "paper wins";
  }
} // don't forget to close else if!!
else if (choice1 == "paper"){

see comment in code above, very important.

I am afraid your code needs some rewriting, if you need more help because you get stuck again, post an updated version of your code


#3

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