Help me understand why this does not work

Tell us what’s happening:
Hi guys I am completely lost with this one. Can someone explain why this doesnt work, I may
be a little slow but It fulfills all the conditions to my knowledge

Your code so far

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

// Only change code below this line
function updateRecords(id, prop, value) {
if(prop == "tracks" && !collection[id].hasOwnProperty("tracks")){
collection[id].tracks = []; 

if(prop == "tracks" && value !== ""){collection[id].tracks.push(value);}
 if(value === ""){delete collection[id][prop];}

 return collection;

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

What happens if the property is “album” or “artist”

So I have to make a condition for when prop is not equal to tracks and set it to value I guess

Yep, not fulfilling that part of the instructions is why you aren’t passing

Thank you it passed now. This took me more than 5 hours. Is that normal for a beginner?.. Is there some material or course for me to get better at this?

Yes, this is normal if you’re a beginner. This isn’t easy to start with. You have to learn to break a problem down into simple parts, then join it back together, covering all of the requirements. Remember what you did wrong and you might not make the same mistake next time there’s something similar. It’ll get easier the more you practice as long that practice is deliberate (ie you’re identifying what you’re unsure about or don’t know and working on that each time, building up.knowledge)

1 Like

Thanks a lot for your words of encouragement. I’ll keep working on it.

1 Like