Exercise 8


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

After i try to run this it just returns the error "Oops, try again. Your code returned 'scissors wins' instead of 'undefined' when the inputs are scissors and rock" please help, i can't find the issue. thanks.


#2

Are you positive this all your code and you are at exercise 8? There are a whole lot of if and else statements missing, maybe redo exercise 6 till 8?


#3

yeah thats what happened. weird though because I've just been hitting next every time, not sure how it skipped. but thanks for catching that.


#4

Mine also skipped without logging it being correct a few time.