Tell us what’s happening:
I don’t know why I get an output of 4, the number of friends (it changes when you add more friends, that’s why I guess it is their count).
I can see my code is a bit different than the solution and I would understand it not working at all, but I don’t understand how I get a number output.
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) {
// Only change code below this line
let newArr = userObj.data.friends.push(friend);
return newArr;
// Only change code above this line
}
console.log(addFriend(user, 'Pete'));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36
.
Challenge: Modify an Array Stored in an Object
Link to the challenge: