A little question about this code formFunctional Programming - Understand Functional Programming Terminology

Hi Everyone !

I hope that you are all well and ready to climb even higher on this marvelous day.
I was wondering if the parentheses were mandatory in this line ?

const teaCup = prepareTea();

Since it can work without them.

Thanks !

Your code so far

// Function that returns a string representing a cup of green tea
const prepareGreenTea = () => 'greenTea';

// Function that returns a string representing a cup of black tea
const prepareBlackTea = () => 'blackTea';

/*
Given a function (representing the tea type) and number of cups needed, the
following function returns an array of strings (each representing a cup of
a specific type of tea).
*/
const getTea = (prepareTea, numOfCups) => {
  const teaCups = [];

  for(let cups = 1; cups <= numOfCups; cups += 1) {
    const teaCup = prepareTea();
    teaCups.push(teaCup);
  }
  return teaCups;
};

const tea4GreenTeamFCC = getTea(prepareGreenTea, 27);
const tea4BlackTeamFCC = getTea(prepareBlackTea, 13);

console.log(
  tea4GreenTeamFCC.length,
  tea4BlackTeamFCC.length
);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Challenge: Functional Programming - Understand Functional Programming Terminology

Link to the challenge:

if you want the output of the prepareTea function, yes, it’s mandatory.
If you write teaCup = prepareTea you are just giving a different name to the function

1 Like

Alright, thanks !

But why is this working then ?

because the program doesn’t do anything in particular with teaCup. Most often tho you will have something break if you have a function when you should have a string.

1 Like

Oh alright ! Thank you for making my vision (and journey) even clearer :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.