Problem with Record-Collection not accepting my solution

Tell us what’s happening:
I’m confused. Everything runs as its supposed to when I check the console - all the answers are correct, yet it keeps telling me something is wrong.
I follow the tutorial given by Beau on YouTube at the same time as I go through this online course - it helps me to learn and I take notes for future reference. Usually I complete the exercises on my own.
But in this exercise I used his code . Maybe I’m missing something and I just can’t see it from looking at it for so long?!

Would love some feedback please as I’d like to understand but also progress through the course!
Thank you

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 object;
}

console.log(updateRecords(collection,5439,"artist","ABBA"));
console.log(updateRecords(collection,5439,"tracks","Take a Chance on Me"));
console.log(updateRecords(collection,2548,"artist",""));
console.log(updateRecords(collection,1245,"tracks","Addicted To Love"));
console.log(updateRecords(collection,2468,"tracks","Free"));
console.log(updateRecords(collection,2548,"tracks",""));
console.log(updateRecords(collection,1245,"albumTitle","Riptide"))


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

Hi @newby,

Inside the updateRecords function, you are updating the property values by using the name of the object i.e collection.
Try updating the property values using the ‘object’ variable instead.

1 Like

Hi,

Your updateRecords function accept 4 parameters: object, id, prop, value.
But you never use the object parameter inside your function, except on return.
So basically your function will return whatever value you give to the object parameter.

1 Like

thank you so much! so obvious!

thank you!! it worked - can’t believe I missed it. Much appreciated :smiley:

1 Like

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