What if choice1 was scissors?


#1


SyntaxError: Unexpected token {


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);
console.log("Player: " + userChoice);

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 (choice1 === "Paper") {
            return "Scissors Wins!";
        }
    }
    else {
        if (choice2 === "Paper") {
            return "Scissors Wins!";
        }
        else {
            return "Rock Wins!";
        }
    }
}

compare(userChoice, computerChoice)


#2

Hi this line

else (choice1 === "Paper") {

the else statement doesn't take any condition (remove (choice1 === "Paper"))


#3

Thank You!
but now it comes up with :
Oops, try again. Your code returned 'Rock Wins!' instead of 'undefined' when the inputs are scissors and paper


#4

this part

    else {
        if (choice2 === "Paper") {
            return "Scissors Wins!";
        }
        else {
            return "Rock Wins!";
        }
    }

this line

    else {

should be

    else if {

like that

else if (condition) {
    if (condition) {

    }
    else {

    }
}

AND

the instruction says..
a. if choice2 === "rock", then "rock" wins.
b. if choice2 === "paper", then "scissors" wins.


#5

Cheers for the help xx


#6

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