Stuck at this challenge,not understand how to solve it

Tell us what’s happening:

  **Your code so far**

// Setup
var collection = {
2548: {
  albumTitle: 'Slippery When Wet',
  artist: 'Bon Jovi',
  tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
2468: {
  albumTitle: '1999',
  artist: 'Prince',
  tracks: ['1999', 'Little Red Corvette']
},
1245: {
  artist: 'Robert Palmer',
  tracks: []
},
5439: {
  albumTitle: 'ABBA Gold'
}
};

// Only change code below this line
function updateRecords(object, id, prop, value) {
if (value === "" ) {
  delete collection[id][prop];
}else if(prop === "tracks") {
  collection[id][prop] = collection[id][prop] || [];
  collection[id][prop].push(value);
}else {
  collection[id][prop]=value;
}
return collection;

}

updateRecords(2468,"tracks", "test")
console.log(updateRecords(collection, 5439, 'artist', 'ABBA'));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:85.0) Gecko/20100101 Firefox/85.0.

Challenge: Record Collection

Link to the challenge:

One thing is that you need to use object instead of collection.

1 Like

Hi, but i dont understand where to use an object.

You have the arguments of object, id, prop, value, but if you look in your function you will see you never use the object argument so when you provide your function the object collection it simply will not use it as you never used the argument of object. Think about why you are using the arguments, and what each argument actually represents.

2 Likes

Also think about what you do not understand because your current question " Stuck at this challenge,not understand how to solve it" Actually makes it harder for people trying to help you because it gives no information. A good question goes a long way, and it’ll make people more likely to help.

1 Like

In the problem you will se that it mentions the tasks as a line of if statements, think about how to write that verbatim in code.

1 Like

In other words, replace all occurrence of “collection” with “object”.

The problem in your code is, you are using the variable “collection”. Ask yourself, where is “collection” even coming from? The answer is nowhere. So why are you using it?

But in your function, “updateRecords”, you are accepting four parameters, namely, “object”, “id”, “prop”, and “value”. In this case, you want to use the “object” variable instead of “collection” (which we already concluded does not exist).

If it’s still confusing to you let me know :slight_smile:

1 Like

Thanks for helping me,i understand what is the wrong thing i was doing in code.i used collection insted of object.:sunglasses:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.