7. What if choice 1 is paper?


#1

Don't know where I did wrong...

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

#2

}
// missing } to close else if
else if (choice1 === "paper") {

and:

else {
    return ("scissors wins");
}
}
// missing } to close function

see comments in code.

if you need more help, post an updated version of your code. make sure to properly nest if and else (to check for choice2) inside else if


#3

It seems that this code makes paper win unless choice1 == rock.
You forgot the '{' after 'if (choice2 === "scissors")'
and closed the else if too soon.


#4

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