Use Destructuring Assignment to Assign Variables from Nested Objects test

I have been able to pass the test but I also noticed that when I add console.log(low), the test will fail:
What could be the problem?

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

// Only change code below this line
  
// const lowToday = LOCAL_FORECAST.today.low;
// const highToday = LOCAL_FORECAST.today.high;
const{today:{low: lowToday, high: highToday}} = LOCAL_FORECAST;
console.log(low)
// Only change code above this line

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

// Only change code below this line

// const lowToday = LOCAL_FORECAST.today.low;
// const highToday = LOCAL_FORECAST.today.high;
const{today:{low: lowToday, high: highToday}} = LOCAL_FORECAST;
console.log(low)
// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36

Challenge: Use Destructuring Assignment to Assign Variables from Nested Objects

Link to the challenge:

This code is wrong, so I would expect it to fail. You aren’t using destructuring to assign the required variables.

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

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

how about the above code?

Ok. But you need to replace the original assignments. You can’t redeclare const like that. And low isn’t defined anywhere, so that console.log can’t work as written.

Edit: ah, you commented some stuff out. Generally, leaving commented out code is bad. It confuses everyone and isn’t value-added. It can also break the tests in some cases.

Okay but I am a bit confused.
I followed the examples given…

Delete this

Use a variable that is defined here.

Okaaaaaay. I should use something like : console.log(lowToday);

1 Like