Passed the test: Understand Functional Programming Terminology, but I have a basic question

const prepareGreenTea = () => ‘greenTea’;

const prepareBlackTea = () => ‘blackTea’;

const getTea = (prepareTea, numOfCups) => {

const teaCups = [];

for(let cups = 1; cups <= numOfCups; cups += 1) {

const teaCup = prepareTea();



return teaCups;


// Add your code below this line

const tea4GreenTeamFCC = null; // :frowning:

const tea4BlackTeamFCC = null; // :frowning:

// Add your code above this line





I tried changing:
const teaCup = prepareTea();
** teaCups.push(teaCup);**

to: **

**And instead it returns the whole function as opposed to the single value. **
Why does that happen, I thought it would be the same.


function sayHello() {
  return "Hello";

This is the name the function is assigned to, so if you check what sayHello is, it will be a function:

> sayHello
[Function: sayHello]

This is how you execute the function (evaluate it to a value), so if you check what sayHello() is, it will be “Hello”:

> sayHello()

Thank you very much, I understood.

I now changed it to:


And it works fine.
Is there any reason we should use the original way by declaring a const first instead of using the method directly?

Bear in mind that this is a contrived example: it doesn’t really do anything that couldn’t be done, as you say, by using it directly. It’s more trying to get you used to splitting things out — in reality, it might be something a lot more complex. And when it’s split out into a separate function, it means you can test that function on its own to check it does the thing you want it to do

1 Like