Completely stuck

Tell us what’s happening:
Unfinished code, but i’m really stuck and lost on how to approach this.

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 != collection.tracks && value != "") {
  var prop = collection.tracks;
  return object;
} else if (prop == tracks || object.tracks == undefined) {
  return object;
}

return object;
}

var id = "";
var prop = "";
var value = "";
updateRecords(collection, 5439, 'artist', 'ABBA');


collection["2468"].tracks = ["1999", "Little Red Corvette"]
collection["1245"].albumTitle = "Riptide";
collection["1245"].tracks = ["Addicted to Love", "Can we still be friends?"];
collection["5439"].artist = "ABBA";
collection["5439"].tracks = "Take a Chance on Me";
delete collection["2548"].artist;
delete collection["2548"].tracks;

console.log(collection["2548"]);

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.88 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

Let’s look at your function:

function updateRecords(object, id, prop, value) {
  if (prop != collection.tracks && value != "") {
    var prop = collection.tracks;
    return object;
  } 
  else if (prop == tracks || object.tracks == undefined) {
    return object;
}

Your function is not modifying the object passed into it. You should be changing the property values of the object before you return the object.

Also, you don’t want to reference collection in your function. Basically, forget that collection even exists. You are only accessing/modifying the object passed into the function. collection is just there to give you an example of what the object passed into your function will look like.

And in your else if condition you have prop == tracks but you haven’t declared/defined tracks anywhere. Besides, I think tracks is supposed to be a string, right, so you’d want it to be prop === 'tracks'.

My first thought is that your code should be inside the updateRecords function.

You can access the album you need via object.id within the function updateRecords. These are the parameters from the arguments to the function.

Then iterate through the album, which is an object (value of key id), and see if it contains prop.

Use conditionals to add prop and value if it prop does not exist. Remember Array methods for updating the tracks props.