Calculate the final value of the
result
variable andalert
the value as a number using one line of code.
function mystery(input) {
var secret = 4;
input += 2;
function mystery2(multiplier) {
multiplier *= input;
return secret * multiplier;
}
return mystery2;
}
function mystery3(param) {
function mystery4(bonus) {
return param(6) + bonus;
}
return mystery4;
}
var hidden = mystery(3);
calling mystery3 gives us return mystery2
with the parameter 3
as the input
:
function mystery2(multiplier) {
multiplier *= 5;
return secret * multiplier;
}
Next we have jumble, which takes hidden
as a parameter, which is really just mystery2
with parameters passed in as above. So, we pass mystery2
as the param
parameter in mystery3
:
var jumble = mystery3(hidden);
function mystery4(bonus) {
return mystery2(6) + bonus;
}
Finally we have result
, which is mystery4
with 2
as its parameter:
var result = jumble(2);
return mystery2(6) + 2;
And to get the final result, we pass 6
as a parameter to mystery2
:
function mystery2(6) {
multiplier = 6 * 5; // 30
return 4 * 30; // 120
}
result
is therefore 120 + 2 = 122