Hi,my code if fine but i dont understand it


How does he know that the userChoice is choice1 ? when i havent defined it anywhere...

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's choice: " + computerChoice);

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




you call the function, in which you supply arguments (to satisfy choice1 and choice2 parameter), so the parameters are basically placeholders until you call the function.


Actually, you did!
Take a look at your last line of code:
compare(userChoice,computerChoice) You called the function named compare() and your parameters replaced all the
choice1 & choice2. Basically Choice1 was replaced by userChoice & Choice2 was replaced with computerChoice

Hope this helped!


i figured that out , but i dident figure out why "choice1,choice2" when i change parameter "choice1" to anything else for example "choooooice" it doesnt work.....how does he know that "choice1" is "userChoice and that "choice2" is "computerChoice" i havent defined that anywhere.... or is it me just being stupid.
also if i change the name of the variable "userChoice" to "myChooooice" it still gives out error...


The reason changing one of the parameters in var compare = function(choice1,choice2){ to anything
else doesn't work is because the rest of the code in your function relies on the proper spelling of your parameters.


var multiply = function(a,b) {
  console.log(a * b);
//Returns 4;
//If you change it:
var multiply = function(a,z) {
  console.log(a * b);
//Now it doesn't understand what b is. (It has been replaced by z)

Hope this helps!


yes,very much, thank you...


You're welcome! Glad I could help :slight_smile: