Modify an Array Stored in an Object BUG

Modify an Array Stored in an Object BUG
0.0 0

#1

I think this is a bug it won’t let me pass the challenge.

I have double check on my inspect element and it’s showing as 3 arrays successfully.


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) {
	userObj.data.friends.push(friend);
	return userObj;
};

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/66.0.3359.181 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


#2

What do the failing tests say?


#3

there is no error on console

the only one is missing challenge goal was that

addFriend(user, “Pete”) should return [“Sam”, “Kira”, “Tomo”, “Pete”]


#4

You’re returning the entire object. The requirement is to return the friends array. That’s why the test is failing. Your return value isn’t what is expected.


#5

You have to use this :
return user.data.friends;

instead of this :
return userObj;


#6

As it mentionned above , you have returned the entire object .