Code meets criteria but doesn't let me pass

I pass all requirements except for this one:
addFriend(user, "Pete") should return ["Sam", "Kira", "Tomo", "Pete"]
But if you look at the log, Pete’s there.

Set-up code

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'
  }
}
};
My solution
function addFriend(userObj, friend) {
return userObj["data"]["friends"].push(friend);
}
Console log
console.log(Object.values(user));

[ 'Kenneth',
  28,
  { username: 'kennethCodesAllDay',
    joinDate: 'March 26, 2016',
    organization: 'freeCodeCamp',
    friends: [ 'Sam', 'Kira', 'Tomo', 'Pete' ],
    location: { city: 'San Francisco', state: 'CA', country: 'USA' } } ]

Challenge: Modify an Array Stored in an Object

Link to the challenge:

have you tried to

console.log(addFriend(user, "Pete"))
1 Like

Yep. It’s there by default and it returns the number 4.

Yep. You aren’t returning what you should be returning.

1 Like

4 is pretty different from the required output

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.