Build a Record Collection - Build a Record Collection

Tell us what’s happening:

I have followed all the required steps for the test to run but some how test 5 has completely failed and I need help to find where my code has gone wrong. Thank you

Your code so far

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

const copyRecordCollection = {...recordCollection};




 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 !== "") {
  
  if (!records[id].hasOwnProperty("tracks")) {
    records[id][prop] = [value]
  }
}else if (prop === "tracks" && value !== "" ) {
  records[id][prop].push(value)
}
return records
}



console.log(updateRecords(recordCollection, 1245, "tracks", "Addicted to Love"));


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36

Challenge Information:

Build a Record Collection - Build a Record Collection

Here are some debugging steps you can follow. Focus on one test at a time:

  1. Are there any errors or messages in the console?
  2. What is the requirement of the failing test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

you have two identical conditions, if the first one is true, do you think the second one will be executed?

1 Like

Thank you for your reply. It solved my problem