Object literas access

Hello there. I’m moving along nicely in my online course but I need help w/ this object literal exercise. I appreciate it.

Exercise explanation:
Object literal help

I’ve tried to access and save the new variable in different ways and I’m stumped w/ what I’ve tried.


Hi, I think something like that could work:

const fullAddress = `${restaurant.address}, ${restaurant.city}, ${restaurant.state} ${restaurant.zipcode}`

If I undenstand it correctly, they just want you to create a new variable which will concatenate the keys of the object so you have the full address in one place. You can use template literals to create such string in javascript.

Since you did not provide any of your non working solution it is hard to guess what you struggle with… feel free to post your solition so we can help you understand what you are doing wrong.

And here is some resource regarding how to work with objects in JS maybe it will help you: Working with objects - JavaScript | MDN


Yes, sorry. Here are some of the code I tried:

let fullAddress = {"address"}
let fullAddress.address
let fullAddress ["address"] (The system didn’t like this one because I didn’t include an =. )

None of those worked.

so the problem is that you are trying to access the properties ofthe fullAddress, but variable with that name does not exists.
You need to create a NEW variable with name fullAddress which will concatenate values of the variable (object) with name restaurant .

you can access the values like this:


and since they want you to create the fullAddress by accessing address, city, state and zipCode, so you can do it like this:

const fullAddress = restaurant.address + ", " + restaurant.city + ", " + restaurant.state + " " + restaurant.zipCode

or you can use template literals:

const fullAddress = `${restaurant.address}, ${restaurant.city}, ${restaurant.state} ${restaurant.zipcode}`

in the first line you shared you probably try to use object destructing, but you are having wrong syntax for that:

const { address, city, state, zipCode } = restaurant

but this will only create a variables with names address, city, state, zipCode and assign values from restaurant object. then you would have to use those to create the fullAddress variables

const fullAddress = address + ", " + city + ", " + state + " " + zipCode

You can learn more about descruting here: Destructuring assignment

I hope it is a more clear now.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.