Understand Functional Programming Terminology JavaScript

I am struggling with this challenge can you please help me point out where I’ve gone wrong and the correct way I should proceed with this challenge.

Your code so far


/**
* A long process to prepare green tea.
* @return {string} A cup of green tea.
**/
const prepareGreenTea = () => "greenTea";

/**
* Get given number of cups of tea.
* @param {function():string} prepareTea The type of tea preparing function.
* @param {number} numOfCups Number of required cups of tea.
* @return {Array<string>} Given amount of tea cups.
**/
const getTea = (prepareTea, numOfCups) => {
 const teaCups = [];

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

 return teaCups;
};

// Add your code below this line
const var tea4GreenTeamFCC = getTea(prepareGreenTea, 27); 
var for tea4BlackTeamFCC = getTea(prepareBlackTea, 13); // :)
// Add your code above this line

console.log(tea4GreenTeamFCC, tea4BlackTeamFCC);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.

Challenge: Understand Functional Programming Terminology

Link to the challenge:

Hint:

var for tea4BlackTeamFCC

Happy Bank Holiday,

I’m having trouble with this challenge can I have help to point out where I’m going wrong and put me in the right direction .

Here’s my code

/**
 * A long process to prepare green tea.
 * @return {string} A cup of green tea.
 **/
var for  prepareGreenTea = () => "greenTea";

/**
 * Get given number of cups of tea.
 * @param {function():string} prepareTea The type of tea preparing function.
 * @param {number} numOfCups Number of required cups of tea.
 * @return {Array<string>} Given amount of tea cups.
 **/
const getTea = (prepareTea, numOfCups) => {
  const teaCups = [];

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

  return teaCups;
};

// Add your code below this line
var for tea4GreenTeamFCC = getTea(prepareGreenTea, 27); 
var for tea4BlackTeamFCC = getTea(prepareBlackTea, 13); // :)
// Add your code above this line

console.log(tea4GreenTeamFCC, tea4BlackTeamFCC);

How do you think what’s for in var for tea4GreenTeamFCC = getTea(prepareGreenTea, 27);?
It was just a const to store array of tea cups

Im sorry to be a pain I still don’t understand what I need to do to pass the challenge this is my code below can i please have some help.

/**
 * A long process to prepare green tea.
 * @return {string} A cup of green tea.
 **/
var for  prepareGreenTea = () => "greenTea";

/**
 * Get given number of cups of tea.
 * @param {function():string} prepareTea The type of tea preparing function.
 * @param {number} numOfCups Number of required cups of tea.
 * @return {Array<string>} Given amount of tea cups.
 **/
const getTea = (prepareTea, numOfCups) => {
  const teaCups = [];

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

  return teaCups;
};

// Add your code below this line
var for tea4GreenTeamFCC = getTea(prepareGreenTea, 27);?
var for tea4GreenTeamFCC = getTea(prepareGreenTea, 27);?
// Add your code above this line

console.log(tea4GreenTeamFCC, tea4BlackTeamFCC);

you have made changes outside the allowed part

then you have syntax errors

this is not how you declare a variabe, is it?

1 Like

I know I’m really struggling with the challenge can you please help me with it please

What have you changed based on what people have said so far? Have you fixed the declaration of tea4GreenTeamFCC?

I’m sorry I’m really struggling with this challenge can you please help me by pointing me in the right direction and the best way to approach this challenge.

The first thing you need to do is fix your variable declarations.

Here is the original code

// Only change code below this line
const tea4GreenTeamFCC = null;
const tea4BlackTeamFCC = null;
// Only change code above this line

Here is your code

// Add your code below this line
var for tea4GreenTeamFCC = getTea(prepareGreenTea, 27);?
var for tea4GreenTeamFCC = getTea(prepareGreenTea, 27);?
// Add your code above this line

You do not declare variables with var for.

I know i declare a variable by var then the name what do I do then that’s what I’m unsure of sorry.

What does your code look like with the variable declarations fixed?

i I think it’s fixed

/**
 * A long process to prepare green tea.
 * @return {string} A cup of green tea.
 **/
var for  prepareGreenTea = () => "greenTea";

/**
 * Get given number of cups of tea.
 * @param {function():string} prepareTea The type of tea preparing function.
 * @param {number} numOfCups Number of required cups of tea.
 * @return {Array<string>} Given amount of tea cups.
 **/
const getTea = (prepareTea, numOfCups) => {
  const teaCups = [];

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

  return teaCups;
};

// Add your code below this line
var tea4GreenTeamFCC = getTea(prepareGreenTea, 27);?
var tea4GreenTeamFCC = getTea(prepareGreenTea, 13);?
var tea4GreenTeamFCC = getTea(prepareGreenTea, 27);?
// Add your code above this line

console.log(tea4GreenTeamFCC, tea4BlackTeamFCC);

You are closer to fixed. You need to

Prepare 27 cups of green tea and 13 cups of black tea and store them in tea4GreenTeamFCC and tea4BlackTeamFCC variables, respectively.

Please use the </> button or backticks ``` when you paste code into the forum so that we can see it correctly.

I am sorry I don’t have a clue what I need to do can you please give a step by step guide for me please if your willing?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

Please use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks are not single quotes.

markdown_Forums

You have a prepareGreenTea function and a tea4GreenTeamFCC variable. You have a prepareBlackTea function and a tea4BlackTeamFCC variable. It should be pretty obvious what variable should be assigned the result of what function.

  1. I’d suggest you reset the code.

  2. Assign to the variable tea4GreenTeamFCC the result of calling getTea with the prepareGreenTea callback and the correct number of cups.

  3. Assign to the variable tea4BlackTeamFCC the result of calling getTea with the prepareBlackTea callback and the correct number of cups.

1 Like

Could I please have some help how to solve this challenge as I’m finding it hard to complete and know what I’ve got to do to pass the challenge, can I please have some help to put me in the right direction.

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;
};

// Only change code below this line
const tea4GreenTeamFCC = getTea(prepareGreenTea, 27); // 
const tea4BlackTeamFCC = getTea(prepareBlackTea, 13); // 
// Only change code above this line

console.log(
tea4GreenTeamFCC,
tea4BlackTeamFCC
);

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

console.log(tea4GreenTeamFCC, tea4BlackTeamFCC);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.

Challenge: Understand Functional Programming Terminology

Link to the challenge:

// Only change code below this line
...
// Only change code above this line

The code you placed between these comments is correct, but you changed code outside of these comments. Changing code outside of these comments will often break the test suite. I’d reset the code and only change the code between these comments just as you have here.