Build a Recipe Tracker - Step 8

Tell us what’s happening:

I am returning a number for each of the getTotalIngrediants function call, but when the code test is run, it says that I am not returning a number.

function getTotalIngredients(recipe){
return console.log(recipe.ingredients.length);
};

getTotalIngredients(recipe1);
getTotalIngredients(recipe2);
getTotalIngredients(recipe3);

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

// User Editable Region

function getTotalIngredients(recipe){
  return console.log(recipe.ingredients.length);
};

getTotalIngredients(recipe1);
getTotalIngredients(recipe2);
getTotalIngredients(recipe3);

// 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/136.0.0.0 Safari/537.36

Challenge Information:

Build a Recipe Tracker - Step 8

Logging something to the console doesn’t return it. Check what the actual return value is when you call the function.

I don’t know what to do to fix it and have been suck on this for a couple of weeks. Could you please provide some more usable insight, such as a code snippet that can get me started?

when you do this you are returning the console.log, not the number

specs say: console: log() static method - Web APIs | MDN that the return value of a console.log is undefined, so that’s what your function is returning

the request for this step is that you return the requested number

This is a usable insight

Check what the actual return value is when you call the function

Do you know how to check what happens when you call a function? There are a few ways you could do this.

Do you have something specific that you do not know how to write?