Hi,
I had to come back and look at this again, to figure out why I was confused because it looks like the function names are happening in parallel. The answer is the last line (12) is trying to teach too many things at once, and there's confusion in it.
Here's one answer:
var people = 100;
var rain = 1;
var sharks = 5;
var fearGenerated = function(numPeeps, rainInInches, numSharks) {
var rainFear = numPeeps * rainInInches;
var sharkFear = numSharks * numSharks * numSharks;
var totalFear = sharkFear + rainFear;
return totalFear;
};
var fear = fearGenerated(people, rain, sharks);
// this is the confusing line
Here's the structure for reference:
var1 = 1
var2 = 2
var3 = 3
functionalExpression = function(varA, varB, varC) {...}
var Variable = functionalExpression(var1, var2, var3)
// this is the confusing line
Step 1: Do some maths
Hope you're good at it. I've used: totalFear = 225
Step 2. Lets look at the right side for starters: fearGenerated(people, rain, sharks)
Previously we learned:
fearGenerated(numPeeps, rainInInches, numSharks)
// functionalExpression(var1, var2, var3)
translates as:
fearGenerated(100, 1, 5)
// functionalExpression(100, 2, 5)
Which is fairly straight forward from earlier lessons. Plug them in, and get a result returned.
But there's a second step because the variables are separated out:
fearGenerated(numPeople, rainInInches, numSharks)
// functionalExpression(varA, varB, varC)
First needs to be substituted for:
fearGenerated(people, rain, sharks)
// functionalExpression(var1, var2, var3)
Finally we substitute the numbers:
fearGenerated(100, 1, 5)
// functionalExpression( 100, 1, 5)
Step 3. Left side: Assign it to a variable (var fear = function();
As a final step, we take the total number (in this case it's 225), and assign it to a variable.
This is kinda necessary for the next lesson, but it appears confusing because:
var fearGenerated = function(numPeeps, rainInInches, numSharks);
closely resembles:
var fear = fearGenerated(people, rain, sharks);
After all, fearGenerated is a function, and we've just done a bunch of substitution.
Because of this, it appears that we are substituting:
- numPeeps -> people -> 100
- rainInInches -> rain - > 1
- numSharks -> sharks -> 5
- and fear(...) for fearGenerated(...)
But we are not: fear is NOT being substituted for fearGenerated.
What is actually happening is:
var fear = fearGenerated(people, rain, sharks);
Is not:
var VariableName = functionalExpression(a, b, c)
//because the word 'function' is missing
It is:
var VariableName = ValueOfAnotherFunction(a, b, c)
the function fearGenerated(people, rain, sharks) runs
Then the total of that it's being assigned to the variableName 'fear'
It's a final step after all of the other substitution has occurred.
Hope that helps.
P