7/9 syntax


#1

var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return "The result is a tie!";
}
else if (choice2 === "scissors") {
return "rock wins";
}
else {
return "paper wins";
}

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

}

Can't seem to find what's wrong with the code. Anyone spot the fault?


#2

Found it:
missed an if statement that was supposed to be in from 6/9 but still allowed me to go to next lesson as correct for some reason


#3

i'm also stuck at this part. do post the answer. thanks


#4

My previous code from the last exercise that was considered correct was:

var compare = function(choice1, choice2) {
if (choice1 === choice2) {
return "The result is a tie!";
}
else if (choice2 === "scissors") {
return "rock wins";
}
else {
return "paper wins";
}

However the correct code is:

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

Don't know why it let me pass. I assumed the whole time the problem was with the second part when it was the first.