Rock, Paper Scissors 5/9


#1

Rock Paper Scissors 5/9


I'm just unsure how the computer knows what choice1 and choice2 are. I understand why we use those instead of userChoice and computerChoice but how does the computer know what the variables choice1 and choice2 mean if we don't declare them before hand?


/*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!";
    }
};


#2

At this point it doesn't since we haven't called the compare function, yet. Eventually, we will call it and pass the userChoice and computerChoice variables as arguments. These will be represented in the function by the two parameters.

compare(userChoice, computerChoice);

#3

So if it doesn't know what choice1 & choice2 are, then how does it even run the code to compare two undefined variables? (choice1 & choice2)

Does the computer just run the code from top to bottom, see that there are two arguments at top, and plug those in to the miscellaneous variables we use for the 'compare' function?

For example, if I switched the position of userChoice and computerChoice, then would choice1=computerChoice and choice2=userChoice?


#4

Yes. The parameters correspond directly with the order of the arguments. This exercise will expect choice1 to be userChoice so don't be changing the order when the time comes to call the function.


#5

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