Choice 1 === Choice 2, I get it works, But I don't know why


#1



var compare = function(choice1, choice2)
{
    if (choice1 === choice2)
    {
        console.log( "The result is a tie!");
       while (choice1 === choice2)
       {
           var computerChoice = Math.random();
        if (computerChoice < 0.34) {
        	computerChoice = "rock";
        } else if(computerChoice <= 0.67) {
	        computerChoice = "paper";
        } else {
	        computerChoice = "scissors";
        } 
        
        var userChoice = prompt("Do you choose rock, paper or scissors?");
        console.log("Computer: " + computerChoice);
       return compare(userChoice, computerChoice);
        break;
       }
    }



If i remove the return, my code will not works correctly. Can anyone explain the reason why?


#2

Compare is a function. Although you have created the function at var compare = function..., that function has to be called. Your return statement is calling the compare function with choice1 equaling the variable userChoice and choice2 as computerChoice. It then returns the result.