Stuck since yesterday

Tell us what’s happening:

tell me what im doing wrong i dont get it

Your code so far


// Setup
var collection = {
2548: {
  album: "Slippery When Wet",
  artist: "Bon Jovi",
  tracks: [
    "Let It Rock",
    "You Give Love a Bad Name"
  ]
},
2468: {
  album: "1999",
  artist: "Prince",
  tracks: [
    "1999",
    "Little Red Corvette"
  ]
},
1245: {
  artist: "Robert Palmer",
  tracks: [ ]
},
5439: {
  album: "ABBA Gold"
}
};

// Only change code below this line
function updateRecords(id, prop, value) {
if (value === "tracks") {
delete collection[id][prop];
} else if (prop === "tracks") {
collection[id][prop] = collection[id][prop] || [];
collection[id][prop].push(value);
} else {
collection[id][prop] = value;
}

return collection;
}


updateRecords(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/84.0.4147.135 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

You only need to change this line which determines when to delete a property.

Here’s what the instructions say:

If value is empty ( "" ), delete the given prop property from the album.

i did i just dont understand what its asking im not good with words i need it explained simply

// Your current code
if (value === "tracks") {
  delete collection[id][prop];
}

The above code does the following, in English

If value is “tracks”, delete the given prop property from the album.

But you need rewrite it so it follows these instructions

If value is empty (""), delete the given prop property from the album.

1 Like

ok i’ll try that and see

your solution is short , nice but you must fix in two places
first
if (value === “tracks”) {// change to value=="" instead of tracks because in the test they ask for If value is empty ( "" ), delete the given prop property from the album//
delete collection[id][prop];
} else if (prop === “tracks”) {
collection[id][prop] = collection[id][prop] || ;// **change this to **
collection[id][prop]=(!(prop in collection[id]))? []:collection[id][prop];//
//means the value of tracks depends on if the tracks is property of recored or not it’s still the same if it’s property if not we add it with empty array //
collection[id][prop].push(value);// push the new value
} else {
collection[id][prop] = value;
}
return collection;
}

Try this

if(collection[id][prop]==null){
    if(prop == "tracks"){
        collection[id][prop] = new Array();
        collection[id][prop].push(value);
     }
    else{
        collection[id][prop] = value;
    }
}

else{
    if(value!="" && prop == "tracks"){
      collection[id][prop].push(value);
   } else{
      delete collection[id][prop];
   }
}
return collection;