Build a Recipe Tracker - Step 7

Tell us what’s happening:

In the next few steps you will work on calculating the average rating, the total ingredients, and the difficulty level for each recipe in the recipes array.

Start by creating a getAverageRating function that takes a single argument, which is an array with ratings. Inside the function, calculate the average rating from the array passed to the function.

Your getAverageRating function must return a number.

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


// User Editable Region

function getAverageRating(rating){
return `${rating} 4.5`
}



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

Challenge Information:

Build a Recipe Tracker - Step 7

hi there, welcome to the forum!

I see you’re probably stuck here?
But can you tell us more about what it is you understand about the issues you are having and what you have tried to resolve it?

For example: Do you need help understanding what is meant by ‘calculate the average’ ?
(we cannot guess how to help if you do not give us more information on what you are thinking and what you are struggling with)