Record Collection Syntax

Tell us what’s happening:

I really feel that something is missing in this explanation, I’ve proceeded pretty easlily in the previous tasks but this one is really make me mad.
I’ve took a look at the solutions but I really can’t understand deeply the syntax.

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 !="") {
  prop = value;
} else if (prop == "tracks" && "tracks" == 0) {
  var tracks = [object[id][prop]];
} else if (prop == "tracks" && value != "") {
  object[id][prop] = [value];
}
return object;
}

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

Challenge: Record Collection

Link to the challenge:

  • If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value .

you are almost there, you need to update the object property tho, not the function parameter


for the other parts I see also some difficulties, but the if conditions seems mostly right. Can you explain what confuses you?

Thanks for your reply.
My difficulties are exactly something you mentioned:

object[id][prop] = value (this is the solution I’ve found on the solution topic)

Why this is an update of the project property? I’m a bit lost here.

object[id][prop] = [value]

Same here, why is it working?

Thanks a lot for you help!

" Hint 3

You can’t push to an array that doesn’t exist. Use hasOwnProperty to check firt. "

I can’t find a way to use this to solve the challenge.

you may want to return a few challenges back and review how to manipulate objects:

Accessing Object Properties with Dot Notation
Accessing Object Properties with Bracket Notation
Accessing Object Properties with Variables
Updating Object Properties
Add New Properties to a JavaScript Object
Delete Properties from a JavaScript Object
Testing Objects for Properties
Manipulating Complex Objects
Accessing Nested Objects

In the Record collection challenge you need to use what you learned from these challenges

Thanks a lot, now I’m digging every here and then into loops and I’m understanding a bit more everyday.