Help SyntaxError: 'return' statement outside of function


#1



It says "SyntaxError: 'return' statement outside of function" and I can't find the problem.


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";
}

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


#2

if (choice1 === "rock"); //remove ;

; after if statement is very bad idea.so remove all ; after if

now here

var compare = function (choice1, choice2) {
    if (choice1 === choice2) {
        return "The result is a tie!"
    }}  here you closed the `compare` function .so remove one }

now close the compare function after

} else if (choice2 === "scissors"): { //here remove :(maybe typo)
             return "Scissor wins!"
         }
}
  //here close the compare function by adding a }

now call the function by giving arguments


#3

Thank you it worked!


#4

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