freeCodeCamp Challenge Guide: Use Destructuring Assignment to Assign Variables from Nested Objects

Use Destructuring Assignment to Assign Variables from Nested Objects


Hints

Hint 1

This challenge requires you to assign object property values to variables of different names.

Hint 2

The two lines declaring lowToday and highToday can be replaced with a single line that handles both values.


Solutions

Solution 1 (Click to Show/Hide)
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 { today: { low: lowToday, high: highToday } } = LOCAL_FORECAST;
// Only change code above this line
48 Likes