Modify an Array Stored in an Object not solved

Tell us what’s happening:

It still shows one error:
addFriend(user, “Pete”) should return [“Sam”, “Kira”, “Tomo”, “Pete”]
What’s wrong??

Your code so far


let user = {
  name: 'Kenneth',
  age: 28,
  data: {
    username: 'kennethCodesAllDay',
    joinDate: 'March 26, 2016',
    organization: 'freeCodeCamp',
    friends: [
      'Sam',
      'Kira',
      'Tomo'
    ],
    location: {
      city: 'San Francisco',
      state: 'CA',
      country: 'USA'
    }
  }
};

function addFriend(userObj, friend) {
  // change code below this line  
  return user.data.friends.push(friend);
  return friend;
  // change code above this line
}

console.log(addFriend(user, 'Pete'));

Your browser information:

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

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

Hi prashantverma22,

Clue here is: Finish writing it so that it takes a user object and adds the name of the friend argument to the array stored in user.data.friends and returns that array.

Like @clarkngo mentioned, there are some mistakes in the way you access and return an array. An argument in a function call does not get evaluated because you’re not even using it in the function body as you think. And you’re returning an argument’s friend value, not the array where it lives.:slight_smile:

1 Like

I got this but still can’t find the solution.Am I supposed to return the “friends” array??

Yes, indeed, these are the instructions, bro :slight_smile:

thanxx :v: …it worked