Basic JavaScript - Record Collection

Tell us what’s happening:

I have gone over my code with a fine-toothed comb and can’t see the issue. I know it will be something basic, but I just can’t spot it. I’d rather know than just pasting the solution to get me through it. Thanks :slight_smile:
Console messages:

// running tests After

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

,

tracks

should have the string

1999

as the first element. After

updateRecords(recordCollection, 2548, "tracks", "")

,

tracks

should not be set // tests completed

Your code so far

// Setup
const 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'
  }
};
function updateRecords(records, id, prop, value) {
  if(prop != "tracks" && value != ""){
    records[id][prop] = value;
  }
  else if(prop == "tracks" && records.hasOwnProperty("tracks") == false){
    records[id][prop]= [value];
  }
  else if(prop === "tracks" && value !== ""){
    records[id][prop].push(value);
  }
  else if(value === "") {
delete records[id][prop];
  }
  return records;
}
updateRecords(recordCollection, 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/105.0.0.0 Safari/537.36 Edg/105.0.1343.53

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

Will this ever be true?

1 Like

I spotted it as soon as I posted lol, knew I would. Thanks for your reply :).

Solution: records[id].hasOwnProperty(“tracks”) == false

1 Like