What is choice1?


#1

Hi, we have defined userChoice and computerChoice. But the instruction requires us to use choice1 and choice2. Does this means the computer automatically equates choice1 to userChoice and choice2 to computer choice automatically?

Also, i tried the whole syntax from that start(right from the first syntax of prompt) and keyed in "rock" when prompted. However, I can see that the computer has "math.random' resulting in scissors and yet i still get the message "The result is a tie!", which should have been "rock wins" logically.

Is there anything i am missing out? Can someone help explain this to me?

Thank you in advance!

:smile:


#2

Well I'll explain how functions work and maybe that will help you understand:

var variable = 20;
var example = function( parameter ) {
    console.log( parameter );
};
example(variable);

So the console sees this.

var variable = 20;

example( 20 );

var example = function( 20 ){
    console.log( 20 );
};

So let's translate what the console is seeing to English.

I know that the variable is equal to 20.
I know that I'm going to the function "example" and putting in a new parameter of "variable" which is equal to 20
I know that I am now calling the function, and replacing "parameter" with "variable" which is equal to 20.
I know that I am running any code in the function where "parameter" is equal to 20.

We can do that with more than one parameter too.

var variable1 = "value1";
var variable2 = "value2";

var example = function(parameter1, parameter2){
    console.log(parameter1 + " " + parameter2);
}
example(variable1, variable2);

Once you call the function, you put in what the new parameters are going to be for the function, ie. variable1, and variable2. The parameters in the function are merely holding points in your code, waiting for values to replace them so the function can do it's magic, and you can call the function over and over with different variables.

var variable1 = "value1";
var variable2 = "value2";
var variable3 = "value3";
var variable4 = "value4";

var example = function(parameter1, parameter2){
    console.log(parameter1 + " " + parameter2);
}
example(variable1, variable2);
example(variable3, variable4);

I know that it wants you to be "D.R.Y" but reusing functions is the main purpose of having a function, otherwise you could just have the code run as is without a function.