Struggling with - Use Destructuring Assignment to Assign Variables from Objects

Struggling with - Use Destructuring Assignment to Assign Variables from Objects
0

#1

I’ve been stuck on this challenge for a day or so, I think I understand the reassignment part, however I looked for the hint and totally do not understand the string prototype thing.

I think thats the step i’m missing?

Your code so far


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

function getTempOfTmrw(avgTemperatures) {
  "use strict";
  // change code below this line
  const tempOfTomorrow = AVG_TEMPERATURES
  const {today , tomorrow} = tempOfTomorrow;
 
   // change this line
  // change code above this line
  return tempOfTomorrow;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 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


#2
const tempOfTomorrow = AVG_TEMPERATURES

This above line is unnecessary

const {today , tomorrow} = tempOfTomorrow;

The issue is with this line. When writing this statement, consider the following syntax:
const {value wanted in object : variable to assign it to} = object where it is located

Using that try and reconstruct your statement


#3

const { 79 : tempOfTomorrow} = AVG_TEMPERATURES;

so when I try this, my code still doesn’t run

// running tests

getTempOfTmrw(AVG_TEMPERATURES) should be 79

destructuring with reassignment was used

// tests completed


#4

Okay I see that I am supposed to use tomorrow as the value however when I do this my code does return 79, however it is not accepted as deconstruction with reassignment, can you tell me why this is?

[quote=“spreti, post:3, topic:232980”]

and when I use tomorrow as my value,
it does return 79, however it does not consider this destructuring can you give me more insight on this?

const { tomorrow : tempOfTomorrow} = AVG_TEMPERATURES;


#5

it looks like in your code:

const { tomorrow : tempOfTomorrow} = AVG_TEMPERATURES;

you are accessing the object AVG_TEMPERATURES directly. Try instead accessing the object that was passed to you as an argument (avgTemperatures)


#6

That was the trick, THANK YOU for your help!!