Problems with 8:undefined?


#1



when its a tie , the message comes out fine : "It's a tie"
however, when it is not a tie, i.e to say there's a winner, the message shown is "undefined"
I want the message "XXX wins!" instead.
Please help!


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);
// games code// 
var compare = function (choice1,choice2) {
   //same choices
   if (choice1 === choice2 ) {
        return "The result is a tie!"
    }
    // if rock is chosen and the opponent choses...
    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" }
    }
    
    else if (choice1 === "Scissors") {
        if (choice2 === "Rock") {
            return "Rock wins" ; }
            else {return "Scissors wins" }
    }

    
};

console.log(
    compare(userChoice,computerChoice)
)


#2

Well, it works, but the comparison is case sensitive, so the only something gets returned is if the user enters Rock, Paper or Scissors (with uppercase first letter), if something else gets entered, none of the condition is true, nothing gets returned, so nothing gets printed


#3

i overlooked that part. thanks so much!