Exercise 8


#1

Exercise 8: What if choice1 is scissors?

Error message: Oops, try again. There was a problem with your syntax.

Can you take a look and see what the errors are?

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

var computerChoice = Math.random();

if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
}
console.log("Computer: " + computerChoice);*/

computerChoice = choice2;
userChoice = choice1;

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

#2

console.log("Computer: " + computerChoice);*/

Looks like the end of this line could be an issue, it should end with just the semicolon.


#3

your functions opening curly bracket:

var compare = function(choice1, choice2) { <- this one

doesn't have a matching closing curly bracket, at it at the end. and the */ is indeed a problem, like already mentioned


#4

I fixed it however it still had error saying that: error: ReferenceError: choice2 is not defined


#5

That is caused by these lines (i missed them):

computerChoice = choice2;
userChoice = choice1;

remove them, you can pass computerChoice and userChoice as arguments when you call the function:

console.log(compare(userChoice,computerChoice));