Please I need detailed explanation to this problem. PLEASE!

I don’t understand the question. Please help

  **Your code so far**
// Setup
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'
}
};

// Only change code below this line
function updateRecords(records, id, prop, value) {
if (records.id == "prop"){

}

console.log(records);
}

updateRecords(recordCollection, 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/103.0.0.0 Safari/537.36

Challenge: Record Collection

Link to the challenge:

Hi.
That’s a big question in this step.
Please specify which part/parts of the task are confusing.

Let us start with this

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

I should be able to solve the rest(maybe) if I understand this. Thanks

Will this work?
if (prop != “tracks” && value == “”){
records.id[“prop”] = value
}

no, as the object doesn’t have a property literally named id. You need to access an object property with the id variable here

1 Like

I was writing some verbose explanations, but I see you have your own theories, which are not so bad. Why don’t you try it?
Then if it won’t work, ask more questions)

1 Like

Thanks. I’ll try it

Any chance you haven’t forgotten the explanation? I might still need it. :see_no_evil:

from what I see most of my explanations were unnecessary

my point is, when we will see more of your code, it will be easier to figure out stuff)

How do I go about this?

Please I need detailed explanation to this problem. PLEASE! - #5 by ilenia.

I got a reply stating that “the object doesn’t have a property literally named id . You need to access an object property with the id variable here”

I don’t know what that means.

This is chunk of code from exercise. What part of it would be an id?

To access it would be records[id]?

Yep. When you did

that was like ‘give me literally something called id’
not a good option for our task

oh, thanks.

I thought the dot and bracket notations did the same thing.

Phew!

my code so far btw…
if (prop != “tracks” && value == “”){
records[id][“prop”] = value
if (prop == “tracks” && records[id][“tracks”] == undefined){
records[id][“tracks”][“”] = value

}

You marked topic with ‘solution’. That usually means you don’t have any more trouble with the step. Is that the case?)

nope!

it was a mistake. Still far from solving this

Keep trying then.
Also when you will post some code, press ctrl-e when typing to do stuff like

this
function updateRecords(records, id, prop, value) {
  //If prop isn't tracks and value isn't an empty string, update or set that album's prop to value.

  if (prop != "tracks" && value == ""){
    records[id][prop] = value;
    }
  //If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it.

  else if (prop == "tracks" && records[id]["tracks"] == undefined){
    records[id][prop][""] = value;
  }

 //If prop is tracks and value isn't an empty string, add value to the end of the album's existing tracks array. 
  else if (prop == "tracks" && value != ""){
   records[id][prop].push(value);
}

// If value is an empty string, delete the given prop property from the album.
else if(value = ""){
  delete records[id].prop
}

What do you think?

What do the tests say?

Not sure if you need undefined here.
Consider refresh memories about hasOwnProperty or do some research about it