It wont work!


#1

It is saying: SyntaxError: Illegal return statement

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

if (choice1 === "scissors") {
    if (choice2 === "rock") {
        return "rock wins"
    }
    else if (choice2 === "paper") {
        return "scissors wins"
    }
}

#2

Hi here
1

else if (choice1 === "rock") {if (choice2 === "scissors") {return "rock wins";}
 else { return "paper wins";}

you missing the closing } for closing the else if statement

2 And here you ha more }than you need

if (choice1 === "paper") { <=== you should begin with else if 
    if (choice2 === "rock")
        {return "paper wins"}
    else { return "scissors wins"}
}
} <=== remove this 
} <== remove this too

3 then

if (choice1 === "scissors") { <=== this should be else if 
    if (choice2 === "rock") {
        return "rock wins"
    }
    else if (choice2 === "paper") {<== this should be else ... so remove the condition  (choice2 === "paper")      
  return "scissors wins"
    }
}

#3

7 posts were split to a new topic: The code has no syntax error warning... but don't show the result