Call your compare function with userChoice and computerChoice as the arguments


#1

I am having an issue i keep getting "Oops, try again. Make sure to call your compare function with userChoice and computerChoice as the arguments!" but it looks like I made all the correct changes from choice1/2 to their equivalents. Any help would be great.

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(userChoice,computerChoice) {
if (userChoice === computerChoice) {
return "The result is a tie!";
}

else if (userChoice === "rock") {

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

}

else if (userChoice === "paper") {

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

}

else if (userChoice === "scissors") {

if(computerChoice === "rock") {
    return "rock wins";
}
else{ 
    return "scissors wins";
}

}
}


Function Problem
#2

Inside the function, use the local variables, choice1 and choice2. That is what the lesson checker expects to see.

Outside of the function, at the end, write a call expression:

compare(userChoice, computerChoice);

If you wish to see the output, log the expression:

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

#3

I am stuck on the same issue with calling the compare function. I called the compare function as instructed as my last line of code. I am getting a syntax error that I can't find. This looks correct to me. Did I do something wrong with my last addition of choice2?
Appreciate you taking a look for me! Thanks!

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


#4

Hi this part

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

Should look like the others

else if (condition) {
     if (condition) {

     }
    else { 

    }

}

#5

Got it...Thank you!
It totally worked now!