Build a Recipe Tracker - Step 11

Tell us what’s happening:

This one got me good, I don’t understand how to assign the values to the properties in recipe1.

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

function getDifficultyLevel(cookingTime) {
  if (cookingTime <= 30) {
    return 'easy';
  } else if (cookingTime <= 60) {
    return 'medium';
  } else {
    return 'hard';
  }
}

const recipe1AverageRating = getAverageRating(recipe1.ratings);
console.log(recipe1AverageRating);

const recipe1TotalIngredients = getTotalIngredients(recipe1.ingredients);
console.log(recipe1TotalIngredients);

const recipe1DifficultyLevel = getDifficultyLevel(recipe1.cookingTime);
console.log(recipe1DifficultyLevel);


// User Editable Region

console.log(recipe1.averageRating);
let recipe1.averageRating = getAverageRating(recipe1.ratings);
console.log(recipe1.totalIngredients);
let recipe1.totalIngredients = getTotalIngredients(recipe1.ingredients);
console.log(recipe1.difficultyLevel);
let recipe1.difficultyLevel = getDifficultyLevel(recipe1.cookingTime);

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:141.0) Gecko/20100101 Firefox/141.0

Challenge Information:

Build a Recipe Tracker - Step 11
https://www.freecodecamp.org/learn/full-stack-developer/workshop-recipe-tracker/step-11

In the previous step you already stored the result of getAverageRating(recipe1.ratings); into the variable recipe1AverageRating. So you don’t need to call the function again, you can just use the previously created variable.

No, I’m wrong I should have double checked this first.

You don’t need to declare the properties, since they are not new variables.

You should have an error in the console?

Oh, you’re right. I’m unsure why I included the let in the first place, removing it made it work. Thanks.

1 Like