Hi there,
I was looking at the getFahrenheit function in the instructions and wondered if I could tweak what was there so that I didn’t have to write the console.log command, like they do, to get it to log the temperature; I wanted to be able to just call a function that would write the sentence for me. So I added a function called summary, as below:
const multiplyByNineFifths = (celsius) => {
return celsius * (9/5);
};
const getFahrenheit = (celsius) => {
return multiplyByNineFifths(celsius) + 32;
};
//my addition
const summary = (celsius) => {
console.log('The temperature is ' + getFahrenheit(celsius) + ' degrees outside.')
};
Now, calling the summary function with a value for the celsius parameter will log the sentence to the console automatically. For example, calling this:
summary(15);
Logs:
The temperature is 59 degrees outside.
But I’m really trying to figure out is how all these functions and parameters work together. For example, when I tweaked the above functions again to remove the celsius parameter from getFahrenheit inside the summary function, like so (just to see what would happen):
const multiplyByNineFifths = (celsius) => {
return celsius * (9/5);
};
const getFahrenheit = (celsius) => {
return multiplyByNineFifths(celsius) + 32;
};
const summary = (celsius) => {
console.log('The temperature is ' + getFahrenheit/* NO CELSIUS*/ + ' degrees outside.')
}
And called the function again:
summary(15);
This is what was logged:
The temperature is (celsius) => {
** return multiplyByNineFifths(celsius) + 32;**
} degrees outside.
Here are my questions:
- When you have a function with a parameter, do you always need to include the parameter any other times you call the function, even if it’s in another function?
- What exactly is happening in the second case to make it log the message it is?
Thanks!