Modify an Object Nested Within an Object

Tell us what’s happening:

Hi, I tried to solve the challenge with a couple of different approaches but I can’t understand why I still can’t resolve the last bit, “The online property is set using dot or bracket notation”.

Any hint? Thanks!

Your code so far


let userActivity = {
  id: 23894201352,
  date: 'January 1, 2017',
  data: {
    totalUsers: 51,
    online: 45
  }
};

// change code below this line
userActivity[ "data" ].online = 45; // 1st attempt

userActivity.data[ "online" ] = 45; //2nd attempt

// change code above this line

console.log(userActivity);

// myStorage.car[ "inside" ].glove

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/modify-an-object-nested-within-an-object

Both of those should work. Not quite sure what it’s looking for - try userActivity.data.online, that’s also valid (and would be the one you’d use in practice as there’s no need for bracket syntax here). Sorry, on phone so can’t test

Thanks for the help.
I reset the page and pasted the solutions again, this time worked. The page just got stuck somehow.
All good.

1 Like

we can also use:
// change code below this line
userActivity[‘data’][‘online’]=45;
// change code above this line

or
// change code below this line
userActivity.data.online=45;
// change code above this line

Hi there. I was wondering why userActivity[2][1] does not work. Can anybody please clarify?