Record Collection/Brain Fire

Tell us what’s happening:
Hi!
So, I have written a bunch of code here, that when I “read” it, in relation to the psuedo-code in the instructions, seems to make sense --when weighed against the information and tutorials I have been finding online. But obviously something is not right.

Not sure where to go from here… Any suggestions?

  **Your code so far**

access nested key values in object literal// Setup
var recordCollection = {
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(records, id, prop, value) {

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


updateRecords(recordCollection, 5439, 'artist', 'ABBA');
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Firefox/78.0

Challenge: Record Collection

Link to the challenge:

Can this second condition ever run?

pop only works on arrays. I think you want to look up delete.

1 Like

you have an issue here too, what are the possible outputs of hasOwnProperty?

1 Like