Modify an Array Stored in an Object help

Modify an Array Stored in an Object help


There is one test I cannot pass:
addFriend(user, “Pete”) should return [“Sam”, “Kira”, “Tomo”, “Pete”]
I am not sure why I am not passing. Can you please explain it to me.
Here is my code so far:

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

function addFriend(userObj, friend) {
  // change code below this line 

  // change code above this line

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


You have two return statements in your function, but only the first one will execute, because once a return statement is encountered/executed, the function is immediately exited.

The first return statement is returning a number instead of an array. To figure out why it is returning a number, read thepush documentation about what kind of value it returns.


When you enter a code block into the forum, please precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.