Home > Back-end >  how do I create a variable that points to a string with an object from another variable? I am a newb
how do I create a variable that points to a string with an object from another variable? I am a newb

Time:03-31

I apologize in advance if I worded the question wrong but I have this issue.

const restaurant = {
    name: 'Ichiran Ramen',
    address: `${Math.floor(Math.random() * 100)   1} Johnson Ave`,
    city: 'Brooklyn',
    state: 'NY',
    zipcode: '11206',
}

I am supposed to create a new variable that contains the address, city, state and zip but I am not to sure how to do that.

So far I've tried:

const fullAddress = address.city.state.zip

but I get an error saying that I have not defined the full address variable. I am really not sure what to do next and I have re-watched the video about 5 times now and I am totally lost. any help would be much appreciated.

CodePudding user response:

Do You mean: const fullAddress = `${restaurant.address}, ${restaurant.city}, ${restaurant.state}, ${restaurant.zipcode}` ? Please notice that it's not creating a binding between an object and a built string.

  • Related