8. What if choice 1 is scissors? Please help


#1



The error code I am getting is: "There was a problem with your syntax."

My code as below:
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 === "rock") {
            return "rock wins";
        }
        else {
            return "scissors wins";
        }
    } 
};

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


#2

HI this line

else if {choice1 === "scissors")

you have a { instead of ( just before choice1


#3

Hi Marco,

You are the MAN!
one last question, I wonder how does the system know that userChoice equals choice1 and computerChoice equals choice2? I didn't define this part and somehow it sill output the return correctly

Thanks!

Eason


#4

HI it's from the compare function

var compare = function (choice1, choice2) {
   ...
}
#call function
console.log(compare(userChoice, computerChoice));

choice1 and choice2 are just argument so then when you call the function compare

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

with userChoice and computerChoice. by punting first userChoice
in the call function it will be choice1 and computerChoice will be choice2.


#6

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