What if choice1 is paper?


#1

here is my code:

/*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);*/

function compare(choice1, choice2){
    if(choice1===choice2) {
        return "The result is a tie!";
    }
    if(choice1==="rock"){
        if(choice2==="scissors")
            return ("rock wins!");
        }else{
            return("paper wins!");
        }
    }
    if(choice1==="paper"){
        if(choice2==="rock")
            return ("paper wins!");
        }else{
            return("scissors wins!");
        }
    }
}

The error is:
SyntaxError: Illegal return statement

I am very very new to programming.


#2

for some weird reason after your if:

if(choice2==="scissors")/* missing here */

you don't have a opening curly bracket ({), while there should be. You have this problem twice


#3

Thanks for the help :slight_smile:
Now i get the error:
SyntaxError: Unexpected end of input


#4

please post an updated version of your code


#5

/*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);*/

function compare(choice1, choice2){
    if(choice1===choice2){
        return "The result is a tie!";
    
    if(choice1==="rock"){
        if(choice2==="scissors"){
            return ("rock wins!");
        }else{
            return("paper wins!");
        }
    }
    if(choice1==="paper"){
        if(choice2==="rock"){
            return ("paper wins!");
        }else{
            return("scissors wins!");
        }
    }
    
}

#6

in case of a tie:

if(choice1===choice2){
        return "The result is a tie!";
/* missing } to close the if statement */

you are missing a } to close the if condition


#7

Thank you :smiley: it is working now