I’m working my way through the rock paper scissors project and there is something I do not understand.
The first two functions created were “getUserChoice” and “getComputerChoice”.
In the function “determineWinner” the two arguments were “userChoice” and “computerChoice”.
What I don’t understand is how “determineWinner” knows that “getUserChoice” and “userChoice” are the same thing and “getComputerChoice” and “computerChoice” are the same thing?
I am a rookie, but I don’t see how they’re connected at all. Shouldn’t “getUserChoice” and getComputerChoice" be used in “determineWinner”?
That kind of thing doesn’t make any sense to me. Why do I keep creating variables when I already have one for the same thing?
I did this a while back and will try to help.
The difference to me is that the getUserChoice and getComputerChoice are functions not variables.
Until you call them, they won’t generate a result. The way you call the functions are by setting the variable computerChoice = getComputerChoice() you are saying hey computer run that getComputerChoice function and store the result in a variable I’ve made called computerChoice.
Later when you run determineWinner() you pass in the 2 variables computerChoice and userChoice which are placeholders holding the results from running the functions getComputerChoice and getUserChoice.
The reason I think this lesson is confusing is the naming of the function and variables are very similar to one another. They can easily be renamed to say computerResult = generateComputerChoice().
Hope this helps!