Back to Freecodecamp

Step 8

curriculum/challenges/english/blocks/workshop-recipe-tracker/66fbcf750a62784cf11f5632.md

latest1.7 KB
Original Source

--description--

Create a getTotalIngredients function that takes a single argument, representing an array with ingredients, and returns the number of ingredients from the array passed to the function.

--hints--

You should create a getTotalIngredients function.

js
assert.isFunction(getTotalIngredients);

Your getTotalIngredients function should have a single parameter.

js
assert.lengthOf(getTotalIngredients, 1);

Your getTotalIngredients function should return a number.

js
assert.isNumber(getTotalIngredients(recipe1.ingredients));

getTotalIngredients(recipe1.ingredients) should return 4.

js
assert.strictEqual(getTotalIngredients(recipe1.ingredients), 4);

getTotalIngredients(recipe2.ingredients) should return 5.

js
assert.strictEqual(getTotalIngredients(recipe2.ingredients), 5);

getTotalIngredients(recipe3.ingredients) should return 3.

js
assert.strictEqual(getTotalIngredients(recipe3.ingredients), 3);

--seed--

--seed-contents--

js
const recipes = [];

const recipe1 = {
  name: "Spaghetti Carbonara",
  ingredients: ["spaghetti", "Parmesan cheese", "pancetta", "black pepper"],
  cookingTime: 22,
  totalIngredients: null,
  difficultyLevel: ""
};

const recipe2 = {
  name: "Chicken Curry",
  ingredients: ["chicken breast", "coconut milk", "curry powder", "onion", "garlic"],
  cookingTime: 42,
  totalIngredients: null,
  difficultyLevel: ""
};

const recipe3 = {
  name: "Vegetable Stir Fry",
  ingredients: ["broccoli", "carrot", "bell pepper"],
  cookingTime: 15,
  totalIngredients: null,
  difficultyLevel: ""
};

recipes.push(recipe1, recipe2, recipe3);

--fcc-editable-region--

--fcc-editable-region--