8/9 help


#1

Oops, try again. Your code returned 'paper wins' instead of 'undefined' when the inputs are scissors and paper. Thats what it says for:

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!";
}

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

    if(choice1 === "paper"){

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

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

};

console.log(compare(userChoice, computerChoice));


#2

if(choice1 === choice2){
        return"The result is a tie!";
    }

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

So here you're choic1 =="rock" does nothing at all the choice2 === "paper" returns paper wins even if the inputs are scissors and rock. And any other case that was not mentioned before will return rock wins which makes anything that follows completely pointless as you can never reach it. Maybe have a look at the hint of 6/9 to see how such a case was intended. The general idea is that you check all possibilities for choice1 and inside these cases handle the options left for choice2.