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: