Build a Recipe Tracker - Step 5

Tell us what’s happening:

I’m stuck on step 5 in Build a recipe tracker. I’ve fiddled with an attempt to do part one of the step, but I’m completely lost. I’ve Googled and went back over the course material, but apparently I’m not grasping it.

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


// User Editable Region

const recipe1Name = {
  name: recipe1,
};
console.log(name);


// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0

Challenge Information:

Build a Recipe Tracker - Step 5

look at the example, it shows how to access the name variable of the person object

you can also review the related lecture

Thanks. I couldn’t find the right lesson. I tried this, but it’s still not happy.

const recipe1Name = {
  recipe1: name;
}

I linked to you the right lesson, you can review it

there you are creating an object, not accessing a property of an existing object

go here to review: https://www.freecodecamp.org/learn/full-stack-developer/lecture-working-with-objects/what-is-an-object-in-javascript-and-how-can-you-access-properties-from-an-object

Sorry I meant I couldn’t find the right lesson until you pointed it out to me. I’m still struggling. Am I right in thinking the . and the [ ] apply to console.log? What I can’t figure out is this.
Access the name properties of both recipe1 and recipe2, and assign them to the variables recipe1Name and recipe2Name, respectively.

If you’ve forgotten how to access the properties of an object, you can always review that topic by googling it. For eg you can read an article like this one

I’ve googled and ducked. It still is coming down to this. You should assign the value of the name property of recipe1 to your recipe1name variable. This is my latest attempt.

const recipe1Name = { 
  name: (recipe1[name]),
};

you are assigning a new object to recipe1Name with a property “name” and value " (recipe1[name])"

The {} brackets are used to create and define an object. You just want to access a property of the object.

Refer to the example code again to see how to use a created object (The last two lines)

console.log(person.name); // John
console.log(person['age']);  // 30

Do you see how the name and age properties are accessed?

Thanks. I do, but I must be dense. I still can’t figure out how to assign them to the recipe1 variable.

I see it now. Let! Thanks for your help.

I see it now. Let! Thanks for your help. Forgot to hit reply. Just as well added in the rest of step 5 and still can’t pass. I get: You should create a recipe1Name variable.

let recipe1Name = recipe1.name;
console.log(recipe1Name);
let recipe2Name = recipe2.name;
console.log(recipe2Name);
let recipe1CookingTime = recipe1.cookingTime;
console.log(cookingTime);
let recipe2CookingTimeookingTime = recipe2.cookingTime;
console.log(cookingTime);
1 Like

glad you were able to do it

Thank you. What a relief. :grinning_face:

Worked better when I had the right variable names. Doh!

2 Likes

Please do not make off-topic comments on other threads.

1 Like

are you still stuck? (I’m not sure if you are or not, it isn’t very clear from what you said)

I am no longer stuck. Thank you.

1 Like