What is Choice 1 is Rock


#1

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

Can someone help me check what is wrong with the code?


#2

this line:

if (choice1===choice2);

you have a ; instead of a {, which should mark the start of the if clause.

Also, at the end, add a } to close the function


#3

Yep, i edited it!
But it still doesn't work
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";
}
}


#4

your function:

var compare=function (choice1,choice2)
{

it doesn't have a matching closing curly bracket (})


#5

I closed the function with the curly on the line below return. The return is closed with the curly after the normal bracket.


#6

Wait ! I solved it, my function must incorporate my else if into such that anything that is part of the function must be in the bracket below it


#7

that is a bit early, shouldn't all comparison be in the compare function? this include the else if for this and the next few lessons, they are all comparisons to determine who won

see step 1 of the instructions:

Inside the compare() function under the existing code, write an else if statement where the condition is choice1 === "rock"


#8

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