1

I am using freecodecamp and my assignment is to "Use destructuring assignment to obtain max of forecast.tomorrow and assign it to maxOfTomorrow." While my code does produce the correct number, the testing program claims I did not use nesting deconstructing. Please take a look at my code and tell me what I need to change. Thank you.

const LOCAL_FORECAST = {
  today: { min: 72, max: 83 },
  tomorrow: { min: 73.3, max: 84.6 }
};

function getMaxOfTmrw(forecast) {
  "use strict";

  const { tomorrow: { max: maxOfTomorrow } } = LOCAL_FORECAST;

  return maxOfTomorrow;
}

console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6

2
  • 2
    Your solution works, but you're using the global variable LOCAL_FORECAST instead of the parameter forecast Commented Aug 7, 2018 at 8:55
  • Thanks Andreas. That made the difference Commented Aug 7, 2018 at 9:06

2 Answers 2

1

You don't need to create a function. You can just deconstruct it immediately.

let {tomorrow: {max: maxOfTomorrow}} = LOCAL_FORECAST

console.log(maxOfTomorrow);
Sign up to request clarification or add additional context in comments.

Comments

0

You could destructure like this:

const { tomorrow } = LOCAL_FORECAST;
const { max } = tomorrow;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.