I do not know what to do

Tell us what’s happening:

   **Your code so far**

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

console.log(updateRecords(collection, 5439, 'tracks', 'Take a Chance on My'));




   **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

Well, this is the case for which it is failing:

updateRecords(collection, 5439, "tracks", "Take a Chance on Me")

This is what you are getting back:

{
  "1245": {
    "artist": "Robert Palmer",
    "tracks": []
  },
  "2468": {
    "albumTitle": "1999",
    "artist": "Prince",
    "tracks": [
      "1999",
      "Little Red Corvette"
    ]
  },
  "2548": {
    "albumTitle": "Slippery When Wet",
    "artist": "Bon Jovi",
    "tracks": [
      "Let It Rock",
      "You Give Love a Bad Name"
    ]
  },
  "5439": {
    "albumTitle": "ABBA Gold",
    "tracks": "Take a Chance on Me"
  }
}

The test fail message says:

After updateRecords(collection, 5439, "tracks", "Take a Chance on Me") , tracks should have the string Take a Chance on Me as the last element.

But this is what you have:

    "tracks": "Take a Chance on Me"

Is that “the last element”? It’s the only element. It’s not even an element - that would imply that it is in an array. But you don’t have an array here, you just have a string.

Can you find in your code where this is handled? I was able to add two characters to that line and get your code to pass. Give it a try and let us know if you need a better clue.

thank you, I did not see that immediately but I get it now

1 Like

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