Part 8 - choice


#1

I pass with the code below but I don't understand how the JS knows what choice1, choice2 are when there's no reference to what choice1 and choice2 are in the function or vars? I replaced the original choice1 and choice2 in the:
var compare = function(userChoice, computerChoice) {

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(userChoice, computerChoice) {
if(choice1 === choice2) {
return "The result is a tie!";

}

else if(choice1 === "rock") {

if (choice2 === "scissors") {
return "Rock Wins";
}
else {
return "Paper Wins";
}
}

else if(choice1 === "paper") {

if (choice2 === "rock") {
return "paper wins";
}
else {
return "Scissors Wins";
}
}

  else if(choice1 === "scissors") {

if (choice2 === "rock") {
return "rock wins";
}
else {
return "Scissors Wins";
}
}
}


#2

Here's how parameters in functions work.

var exampleFunction = function( parameter1, parameter2 ) {
   //code here
};

exampleFunction(variable1, variable2);

after you right that the function would go through like so. Let's say I want to have variable1 be userChoice, and variable2 to be computerChoice, well I'd put it in like this.

var exampleFunction = function( parameter1, parameter2 ) {
   //code here
};
exampleFunction(userChoice, computerChoice);

What the console sees is this.

exampleFunction(userChoice, computerChoice); 
/*It sees this and already knows exampleFunction Exists.*/
var exampleFunction = function( userChoice, computerChoice);
//It replaces "parameter1", and "parameter2" respectively
//lastly, it goes through and replace anywhere parameter1, or parameter2 showed up 
//with userChoice, and computerChoice. Again this is respective of how you structure
//your function