NEW: Use Destructuring Assignment to Assign Variables from Objects

Tell us what’s happening:

Not sure why its wrong, the console log is returning correct answer. Is it something about it needing to be ‘inline’? I don’t know how to do that…

Your code so far


const AVG_TEMPERATURES = {
  today: 77.5,
  tomorrow: 79
};

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  
  const {tomorrow: temp2} = AVG_TEMPERATURES;
  const tempOfTomorrow = temp2;
  console.log(tempOfTomorrow); // change this line
  // change code above this line
  return tempOfTomorrow;
}

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79

console.log(getTempOfTmrw(AVG_TEMPERATURES)); // should be 79

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36.

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

Two things,

  1. don’t use temp2, just assign directly to tempOfTomorrow - what you did is technically correct, just the tests are checking for what you wrote and they expect you to don’t use an intermediate variable
  2. don’t use the global object, when you are in a function and the object you are working on is being passed in as function argument, you need to reference it with the function parameter
1 Like

superstar as usual, so fast in replies which is extremely valuable toward continuity, much obliged.