Build a Recipe Tracker - Step 7

Tell us what’s happening:

it was asking like this
Your getAverageRating function should return a number. 4. getAverageRating(recipe1.ratings) should return 4.5. 5. getAverageRating(recipe2.ratings) should return 4.75. 6. getAverageRating(recipe3.ratings) should return 4

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


// User Editable Region

recipes.push(recipe1, recipe2, recipe3);
function getAverageRating(ratingsArray) {
  // Calculate the average rating and return it
  const average = ratingsArray.reduce((sum, current) => sum + current, 0) / ratingsArray.length;
  return average; // ✅ return the number (not console.log)
}

getAverageRating(recipe1); 
getAverageRating(recipe2); 
getAverageRating(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/141.0.0.0 Safari/537.36

Challenge Information:

Build a Recipe Tracker - Step 7

When you call getAverageRating(), you should be passing in the ratings array, not the recipe object.