What am I doing wrong?


#1

This is my code: what am I doing wrong? I'm getting the error "illegal return statement"
var compare = function (choice1, choice2){if (choice1===choice2){return "The result is a tie!";}
else if(choice1==="rock" && choice2==="scissors"){return "rock wins!"} else{return "paper wins!"}
}
if(choice1==="paper" && choice2==="rock"){return "paper wins"}
else {return "scissors wins"}
}


Rock, Paper, Scissors
Rock, Paper, Scissors
#2

var compare = function (choice1, choice2){
    if (choice1===choice2){
        return "The result is a tie!";
    }else if(choice1==="rock" && choice2==="scissors"){
        return "rock wins!"     
    } else {
        return "paper wins!"
    }
} //Your compare function is closed here - it shouldn't be
if(choice1==="paper" && choice2==="rock"){
    return "paper wins" //This return statement is illegal because you cannot use return
} else {                //outside of a function.
    return "scissors wins"
}
}

#3

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