Build a Record Collection - Build a Record Collection

Tell us what’s happening:

Hello, Hello

This is my second ask for help moment in a week. So I feel rather defeated rn.

To my understanding my new array is just empty, and not updating to the inputed track title.
My question is is my line records[id].tracks.push(value) is this not the correct way to update the input of the track

Thank you

Your code so far

const recordCollection = {
  2548: { // id number 
    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'
  }
};

function updateRecords(records, id, prop, value) {

  if (value === '') {
    delete records[id][prop];

  } else if (prop !== "tracks" && value !== "") {
    records[id][prop] = value;

  } else if (prop === "tracks" && value != "") {
    records[id].tracks = [];
    
  } else if (prop === 'tracks' && value !== '' && records[id].hasOwnProperty("tracks")) {
    records[id].tracks.push(value);
  }

  return records
}
console.log(updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"))

updateRecords(recordCollection, 2468, "tracks", "Free")

updateRecords(recordCollection, 1245, "tracks", "Addicted to Love")



Your browser information:

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

Challenge Information:

Build a Record Collection - Build a Record Collection

Asking questions is good - no need to feel bad about it

That line looks ok to me. I have an issue with this one though

Also, your logic for your if conditions isn’t quite right.

Thank you for the confidence boost.
Please let me ask are you telling me I am completing the question 5 but not the question 4 ?? May that is my mix up then

okay so I updated the line you told me to loon into.
I had in the 3rd else if:

} else if (prop == “tracks” && value != “”) {
records\[id\].tracks = [ ];
and I adjusted it to:
} else if (prop == “tracks” && value != “”) {
records\[id\].tracks = \[value\];

which worked well now I need to fulfill the 6th request, which has to do with the beginning on my array

Okay I have been looking at this for awhile and I am still not able to wrap my head around it.
I am not able to fulfill 6, but in the console log print the date 1999 is listed first

Updated Code:

function updateRecords(records, id, prop, value) {

//this is the 2 requirement

if (value === ‘’) {

delete records\[id\]\[prop\];

// this is the 3 requirement

} else if (prop !== “tracks” && value !== “”) {

records\[id\]\[prop\] = value;

} else if (prop == “tracks” && value != “”) {

records\[id\].tracks = \[value\];

// this is the 4th requirement

// if there is a prop, not value but has a track to add to the collection

} else if (prop === “tracks” && value !== “” && records[id].hasOwnProperty(“tracks”)) {

records\[id\].tracks.push(value);

}

return records

}

console.log(updateRecords(recordCollection, 2468, “tracks”, “Free”))

Are these in the right order? To put it another way, can you ever reach the final else-if case?

Okay wow, I guess it is something simple.

Thank you very much

1 Like