8. What if choice1 is scissors?


#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 === "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 === "paper") {
        return "rock wins";
    }
    else {
        return "paper wins";
    }
}

};
compare(userChoice, computerChoice);

Not sure what i have wrong here would greatly appreciate some help!
Im getting Oops, try again. There was a problem with your syntax.
Thanks for the help!!!


#2

Hi I'm getting these error like

Oops, try again. Your compare function does not return 'The result is a tie!' when there is a tie.

Any idea below is my code.
/*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";
}
};

-Thanks in advance


#3

Try to insert exclamation mark after word "tie".


#4

Thanks for your help elv1nas


#5

Hi codedami0n,

I was also facing the same issue , i have delete the last else if statement it is working.
If its work please let me your feedback.


#6

missing parenthesis
on your scissors else if