Need clarification on 6. return II example


#1

Could anyone explain to me how the function multiplyByNineFifths(celsius) understands to use the 15 degrees argument from the Fahrenheit function? At no point is there any line with multiplyByNineFifths(15).

I can't wrap my head around the steps the program takes in this example. How does the argument of one function apply to the other?


function multiplyByNineFifths(celsius) {
  return celsius * (9/5);
}

function getFahrenheit(celsius) {
  return multiplyByNineFifths(celsius) + 32;
}

console.log('The temperature is ' + getFahrenheit(15) + '°F');
// Output: The temperature is 59°F


#2

This function header has a parameter, celsius ...

function getFahrenheit(celsius)

When you make this call ...

console.log('The temperature is ' + getFahrenheit(15) + '°F');

... that 15 between the parentheses gets assigned to the parameter celsius of the getFahrenheit function.

Then, inside that function we have this ...

return multiplyByNineFifths(celsius) + 32;

That variable, celsius, is the same variable as the parameter, celsius, and therefore has the value 15. That is how the value of 15 gets passed to the multiplyByNineFifths function.

This gets the result evaluated and returned back to the getFahrenheit function where it called the multiplyByNineFifths function ...

return celsius * (9/5);

#3

Thank you for the reply, I can see the steps a lot more clearly now. Had to step back for a day to read this with a clear mind. Much appreciated!


#4