Getting stuck with destructering

Tell us what’s happening:
Can’t figure out where i got wrong. Could use some help here.

Your code so far


const LOCAL_FORECAST = {
yesterday: { low: 61, high: 75 },
today: { low: 64, high: 77 },
tomorrow: { low: 68, high: 80 }
};

// change code below this line
const{lowToday, highToday {today.low,  today.high}} = LOCAL_FORECAST;


// change code above this line

console.log(lowToday); // should be 64
console.log(highToday); // should be 77

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15.

Challenge: Use Destructuring Assignment to Assign Variables from Nested Objects

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-assign-variables-from-nested-objects

you shouldn’t use dot notation in this, also the format is wrong il give you an example

const { johnDoe: { age: userAge, email: userEmail }} = user;

this is the format you want, so instead of user you have LOCAL_FORECAST and instead of johnDoe you have today like so

const {today: { Destructuring goes here }} = LOCAL_FORECAST

i think you should be able to work the rest out now :slightly_smiling_face:

2 Likes

Hello Senkora.

It would help you to really pay attention to the example code in the lesson. Essentially, you are taking values from the object, and assigning them to new variables lowToday and highToday. You already know how to access values from objects - Start from there.

Access the key you want, then add it to the new variable names. Remember: You are not so much accessing a value, as you are accessing a key with an associated value. So, take the key, and give it a knew name.

Click for answer:

const {today: {low: lowToday, high: highToday}} = LOCAL_FORECAST;

I hope that makes sense.

1 Like

Thanks I was able to sollute thanks to you. Got a bit confused but the structure is more like
low: keyWord, high: keyWord

1 Like