Basic JavaScript - Record Collection

Can anyone help me here
when I hit “Run the tests” it gives me an error on the first and last test, but when I manually check it with console.log its returning the result they asked for…
What am I doing wrong? I’m stuck.

// 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'
}
};

// Only change code below this line
function updateRecords(records, id, prop, value) {
if(prop !== "tracks" && value !== ""){
 return prop = value;
}
else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === false){
  return records[id][prop] = [value];
}
else if(prop === "tracks" && value !== ""){
   records[id][prop].push(value);
}
else if(value === ""){
  delete records[id][prop];
}
return records; 
}

console.log(updateRecords(recordCollection, 5439, "artist", "ABBA")); 

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

I’ve tried to run the failing tests with your code. It doesn’t seem the object with collection is changed after running them. Print out the recordCollection to the console, and take a look.

console.log(recordCollection);

Hi @Xero. I hope you already found a solution. If not, you can find the solutions by clicking Get Help > Get a hint in the challenge. As I see it, in the first condition, you need to use records[id][prop] = value;. That should resolve the errors.

Happy coding!

I’ve tried it but now its giving me another failed test

nvm it’s working now. thank you boba!

1 Like