What if choice1 is paper?


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661


I don't know what's wrong with the part. if i submit it, there's always a message : SyntaxError : missing } after function. I honestly don't know where.


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

Here

You're missing the last curly brace for the function. I have corrected as below.

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

#3

Well, thanks for reminding me, I've been twiddling with this part for hours with no progress.
maybe I drift off too far for now, hahaha.
Thanks btw


#4

Haha... You're welcome.

Have fun coding!


#5

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