Build a Recipe Tracker - Step 9

Tell us what’s happening:

Hi, may I know why this is still wrong? Thanks…

Your code so far

const recipes = [];

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

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

const recipe3 = {
  name: 'Vegetable Stir Fry',
  ingredients: ['broccoli', 'carrot', 'bell pepper'],
  cookingTime: 15,
  totalIngredients: null,
  difficultyLevel: '',
  ratings: [4, 3, 4, 5],
  averageRating: null,
};

recipes.push(recipe1, recipe2, recipe3);

function getAverageRating(ratings) {
  const total = ratings[0] + ratings[1] + ratings[2] + ratings[3];
  return total / ratings.length;
}

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


// User Editable Region

function getDifficultyLevel(cookingtime){

if(cookingtime <= 30){

  console.log("easy");

} else if(cookingtime => 31 && cookingtime <= 60){

  console.log("medium");

} else{

  console.log("hard");

}

};

console.log(getDifficultyLevel(31))

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0

Challenge Information:

Build a Recipe Tracker - Step 9

1 Like

Hi @timduncan0322

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

Returning something and console logging it are two different things.

If a function returns undefinedthen it is not returning anything except a default response.

Happy coding

Thanks, totally forgot about the return line, however it seems still doesn’t work after this, any advice? Thanks.

function getDifficultyLevel(cookingtime){

if(cookingtime <= 30){

console.log(“easy”);

} else if(cookingtime > 30 && cookingtime <= 60){

console.log(“medium”);

} else{

console.log(“hard”);

}

return cookingtime

};

console.log(getDifficultyLevel(60));

you are not returning the difficulty, you are returning cookingtime, which is not what the function should do

Got it , thanks again :+1: