Please Help with Record Collection

Hi,
Can someone please check my code and tell me whats wrong with this.
Thanksyou


// Setup
var collection = {
 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(object,id, prop, value) {
if(value=""){
  delete object.[prop];
  console.log(object[id]);
}
else{
if(prop!="tracks"){
 object[id][prop]=value;
 console.log(object[id]);
}
else if(prop=="tracks" && object[id].hasOwnProperty==false){
 object[id][prop]=[];
 object[id][prop]=value;
 console.log(object[id]);
}
else if(prop=="tracks" && object[id].hasOwnProperty==true)
{
 object[id][prop].push(value);
 console.log(object[id]);
}

}

  return object;
  }
  
updateRecords(collection, 5439, "tracks", "Take a Chance on Me");
updateRecords(collection, 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/87.0.4280.141 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

this is not checking the value, = is the assignment operator, you need to use the comparison
operator ===

this is wrong syntax, you can’t use dot and bracket notation at the same time

you may want to check the rest for other errors of the same kind

1 Like

object.prop cannot find the property of the array. You need to access to id first. So the code becomes: object[id][prop].

1 Like

Thankyou Friends for the help, its resolved now.

have you corrected these too?

Yes, after i have pasted it here. I went back and analyzed the code before reading your comments. Hence i was able to resolved it on my own.

good job!

happy coding

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.