Functional programming question


printed 40 greenTea, I want to know why it is printing greenTea

  **Your code so far**

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

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 = (numOfCups) => {
const teaCups = [];

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

// Only change code below this line
const tea4TeamFCC = getTea(40);
// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Linux; Android 11; SM-P615) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

Challenge: Learn About Functional Programming

Link to the challenge: text

Please help. Thank you.

const tea4TeamFCC = getTea(40)

prepareTea is a function that returns the string “green tea”, that’s all.

getTea is a function that takes a number, then loops that many times, running prapareTea (which is the string “green tea” and pushing the result into an array, then returns the array

run getTea(2)
  create empty array
    first iteration:
      run prepareTea
      result is "green tea"
      push "green tea" into array
      array is now ["green tea"]
    second iteration:
      run prepareTea
      result is "green tea"
      push "green tea" into array
      array is now ["green tea", "green tea"]
  end loop
  return array

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