Tell us what’s happening:
Can anyone tell me why my code is returning an empty string?
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 result = [];
for (const props1 in userObj){
if (userObj[props1] == 'data' ){
for (const props2 in userObj[props1]){
if(userObj[props1][props2]== 'friends') {
let resultT = userObj[props1][props2].push(friend);
result = [...resultT];
}
}
}
}
return result
// Only change code above this line
}
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/120.0.0.0 Safari/537.36
Challenge Information:
Basic Data Structures - Modify an Array Stored in an Object