Back to Freecodecamp

Step 10

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

latest2.2 KB
Original Source

--description--

It's time to test each of the functions. You can use any of the recipes for this, but this tutorial will start with recipe1.

Create two new variables: recipe1TotalIngredients and recipe1DifficultyLevel. Assign them the values by calling the corresponding function for each variable and passing in the appropriate recipe1 property.

Finally, log each variable to the console to see the results.

--hints--

You should create a recipe1TotalIngredients variable.

js
assert.isNotNull(recipe1TotalIngredients);

Your recipe1TotalIngredients variable should be set to getTotalIngredients(recipe1.ingredients).

js
assert.equal(recipe1TotalIngredients, getTotalIngredients(recipe1.ingredients));

You should log recipe1TotalIngredients to the console.

js
assert.match(code, /console\.log\(recipe1TotalIngredients\);?/);

You should create a recipe1DifficultyLevel variable.

js
assert.isNotNull(recipe1DifficultyLevel);

Your recipe1DifficultyLevel variable should be set to getDifficultyLevel(recipe1.cookingTime).

js
assert.equal(recipe1DifficultyLevel, getDifficultyLevel(recipe1.cookingTime));

You should log recipe1DifficultyLevel to the console.

js
assert.match(code, /console\.log\(recipe1DifficultyLevel\);?/);

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

function getTotalIngredients(ingredients) {
  return ingredients.length;
}

function getDifficultyLevel(cookingTime) {
  if (cookingTime <= 30) {
    return "easy";
  } else if (cookingTime <= 60) {
    return "medium";
  } else {
    return "hard";
  }
}

--fcc-editable-region--

--fcc-editable-region--