Stuck on Record Collection

Either tracks or artist. That’s why I have the tracks bit to specify that I’m trying to push value to tracks.

and how do you know that’s one or the other?

1 Like

Getting closer

Issue here. Is records[id][prop] an object?

Issue here. If prop ==='tracks' does this make sense?

These two conditions contradict each other. When do you want to create the array?

If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.

Issue here. Is records[id][prop] an object?

I’ve swapped all the records[id][prop].hasOwnProperty for records.hasOwnProperty.

Issue here. If prop ==='tracks' does this make sense?

I know that means if prop is strictly equal to tracks, but not how to use that information in my code.

These two conditions contradict each other. When do you want to create the array?

To me it reads like the lesson requirement contradicts itself, therefore my code does because I’m trying to do what the lesson says. I know I want to create the array if prop is tracks and the album has no tracks property. But I don’t know how to not write contradicting code when that seems to be what I’m being asked to do.

which requirement do you think contradict itself?

can records have a tracks property?

1 Like

Close. records is an object with objects inside of it. records never has any 'tracks', only an individual record given by the id number can have 'tracks'.

In that case you are saying records[id]['tracks']['tracks']

I still think you are mixing up a little but what every variable means.

This is talking about the prop variable

This is talking about the individual record from records

It doesn’t contradict itself, I’m just being a muppet.

If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.

That just means if the prop is tracks, but there aren’t any tracks properties i.e. artists, create an empty array. (I hope).

I thought it could? If not I’m totally lost what I’m supposed to be doing instead.

tracks is not artist, so it can’t be the same thing

  // log some information about the arguments
  // -- id number of the record
  console.log("id:", id);
  // -- property to update
  console.log("prop:", prop);
  // -- value to set for the property, or "" to delete
  console.log("value:", value);
  // -- the full record collection
  console.log("records:", records);
  // -- the specific record to update
  console.log("records[id]:", records[id]);
  // -- the current value of the property
  console.log("records[id][prop]:", records[id][prop]);

I’ve got this now but the whole thing fails every test. I am completely lost now. I’m taking a break because I am getting really frustrated at myself again that I still cannot do this challenge after weeks of practising really hard.

// Only change code below this line
function updateRecords(records, id, prop, value) {
  if (prop !== "tracks" && value !== '') {
    // correct
   [id][prop] = value;
  } 
  else if ([id][prop].hasOwnProperty('tracks') && [id][prop]['tracks'].hasOwnProperty == false) { 
// correct
       [id][prop] = [value];
  } 
  else if ([id].hasOwnProperty('tracks') && value != '') { // also small tweak needed here
    // looks mostly good - small tweak needed
    [id][prop].hasOwnProperty('tracks').push(value);
  } 
  else if (value == '') {
    // looks good
    delete [id][prop];
  } 
    // correct
    return records;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');

Woah, slow down… You keep clobbering syntax that you previously had correct. You need to reference the records.


// Only change code below this line
function updateRecords(records, id, prop, value) {
  if (prop !== "tracks" && value !== '') {
    // 100% correct
    records[id][prop] = value;
  } 
  else if (records[id][prop].hasOwnProperty('tracks') && records[id][prop]['tracks'].hasOwnProperty == false) { 
    // The condition above needs fixing
    //  The part below is correct
    records[id][prop] = [value];
  } 
  else if (records[id][prop].hasOwnProperty('tracks') && value !== '') {
    // The condition will need a similar fix to above 
    // The [prop]['tracks'] part is wrong, the rest is correct
    records[id][prop]['tracks'].push(value);
  } 
  else if (value == '') {
    // 100% correct 
    delete records[id][prop];
  } 
  // 100% correct 
  return records;
}

You really have two issues left

  1. You need to be able to write this condition into code

If prop is 'tracks' but the album doesn’t have a 'tracks' property

I think that you understand the first part

If prop is 'tracks'

It isn’t in your code yet, but you have checked if a variable is equal to some specific value before in other parts of this challenge.

But the second part is a bit off in your code

You want to know if ‘the album’ (the one that you are modifying, the idth record) has the property 'tracks'. You need to drop some []s (not all of them!) and you need to add an argument to hasOwnProperty.


  1. You need to push onto the correct place.

You have this

But above you have

Big picture here, in this challenge, you’re updating records[id][prop] and returning the records object. All of your cases should reference this, but the specific values of the function arguments will make sure that you change the right part of the records.


You really have much better code than the first time you tried this challenge. You are learning a lot. Programing is frustrating. That’s the nature of the beast. People don’t like getting stuck, but code stuff gets us stuck regularly. It’s annoying; it’s stupid; but you are getting better at this stuff.

2 Likes

I did it!!! I did it!!! :smiley: :tada:

I’m going to take this to codepen and play with it so I’m sure I fully understand.

3 Likes

Huzzah! Nice work!

2 Likes

That’s awesome @Griff !
Your persistence and hard work paid off because you have a much better understanding of the concepts.

Keep up the good work! :slight_smile:

3 Likes

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