Record Collection Challenge: Completely Stuck

Tell us what’s happening:
My code is not passing and I just can’t figure out why. :frowning:
I’ve read the hints and solutions of other people after getting stuck for an hour and still can’t figure my issue out.

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 (value == "") {
  delete collection[id][prop];
} else if (collection[id][prop] != "tracks") {
  collection[id][prop] = value;
} else {
  collection[id].hasOwnProperty("tracks") ? collection[id].tracks.push(value) : collection[id].tracks = [value];

return collection;

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/83.0.4103.61 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

It appears that your code isn’t properly pushing the value to tracks, but instead setting the value of tracks.
So instead of getting an array, you’re removing the array and setting the value from the function.

are you sure this is the thing you want to check?

1 Like

I’m pretty sure, yeah. Outside the “tracks” part under the else statement, the rest of the code is working properly. This is what I’m getting:

After updateRecords(5439, "tracks", "Take a Chance on Me"), tracks should have "Take a Chance on Me" as the last element.
After updateRecords(1245, "tracks", "Addicted to Love"), tracks should have "Addicted to Love" as the last element.
After updateRecords(2468, "tracks", "Free"), tracks should have "1999" as the first element.

Whoa… I’m confused as to why that is happening though. Doesn’t the question mark statement push if the property exists or creates an array with the value inside if it is not?

don’t you want to check what is the value of prop?
because, try to add console.log(collection[id][prop]) as first line of your function, that will never have value of "tracks"

1 Like

Thank you for your patience. That was indeed the problem. I can’t believe I spent over an hour over something so simple. You’re a lifesaver! :grin: