Back to Freecodecamp

Step 9

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

latest2.3 KB
Original Source

--description--

Create a getDifficultyLevel function that takes a number indicating the cooking time as a parameter.

If the cooking time is less than or equal to 30, the function should return "easy". If it is less than or equal to 60, the function should return "medium". Otherwise, the function should return "hard".

--hints--

You should create a getDifficultyLevel function.

js
assert.isFunction(getDifficultyLevel);

Your getDifficultyLevel function should have a single parameter.

js
assert.lengthOf(getDifficultyLevel, 1);

Your getDifficultyLevel function should return "easy" when the cooking time is less than or equal to 30.

js
assert.strictEqual(getDifficultyLevel(10), "easy");
assert.strictEqual(getDifficultyLevel(20), "easy");
assert.strictEqual(getDifficultyLevel(29), "easy");
assert.strictEqual(getDifficultyLevel(30), "easy");

Your getDifficultyLevel function should return "medium" when the cooking time is greater than 31 and less than or equal to 60.

js
assert.strictEqual(getDifficultyLevel(31), "medium");
assert.strictEqual(getDifficultyLevel(40), "medium");
assert.strictEqual(getDifficultyLevel(50), "medium");
assert.strictEqual(getDifficultyLevel(60), "medium");

Your getDifficultyLevel function should return "hard" when the cooking time is greater than 60.

js
assert.strictEqual(getDifficultyLevel(61), "hard");
assert.strictEqual(getDifficultyLevel(65), "hard");
assert.strictEqual(getDifficultyLevel(70), "hard");
assert.strictEqual(getDifficultyLevel(75), "hard");

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

--fcc-editable-region--

--fcc-editable-region--