Next Steps does not go anywhere


#1

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

SyntaxError: expected expression, got keyword 'if'


var userChoice = prompt("Which do you choose: rock, paper or scissors?");

var seeit = function (userChoice) { //seeit starts here
    if (userChoice === "rock") {
        return True
    } else if (userChoice === "paper") {
        return True
    } else if (userChoice === "scissors") {
        return True
    } else {
        return False;
        console.log("Sorry, your choice is not valid. Please choose from rock, paper or scissors");
        userChoice
    }

}

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 (choice1 === "scissors") {
        if (choice2 === "paper") {
            return "scissors wins";
        } else {
            return "rock wins";
        }
    }
}

compare(userChoice, computerChoice);


#2

HI this line

var compare = function (choice1, choice2)

its missing the open { of the compare function then here

    else if (choice1 === "paper") {
            if (choice2 === "rock") {
                return "paper wins";
            } else {
                return "scissors wins";
            }
        }
    }  <-- #Remove thsi one }

#3

Thank you. Corrected them, but still does not work. What "expression" would the program expect, and what is wrong with "else"?
I suppose that "else" is in seeit part. because that part is the new addition.


#4

Check the comment, code should run now :slight_smile:

Not sure if the seeit function will work the way you intend it to.


#5

It worked. Thank you! :slight_smile: Reading your comment, tried a wrong input. Seems it was ignored. Well, I will go ahead and learn more.

Seems I can not to replay your later post. Thank you that resource is really helpful.


#6

I thought this link might come in handy for your seeit function :slight_smile:


#7

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