I know this is totally wrong but I am still figuring it out

Tell us what’s happening:
I know this answer is totally off, but I have spent several hours trying to figure it out. Originally I couldn’t figure out anything and I had so much confusion. So far this problem has taught me, not to get overwhelmed right away and take a step back. After I spent a day looking at it, I seriously felt SOOOOO stupid that I couldn’t come up with anything. Now I have filled in all the blanks and even though it is all totally wrong, I had to do a lot of thinking through it. I am just proud of myself for getting this far. I still don’t want to look at the solution yet because I don’t have even a single check mark…I will have to look at what other people have reviewed for the problem to see if it makes more sense seeing how others are trying to break it down for us noobies. I just want to say if you are stuck on this one! Keep trying!

My current issues:
I need to figure out how to update the given value to be the value of the property listed.
I had this : recordCollection.prop[value];
Then I tried: recordCollection.id.prop[value];
Trying to figure out how to update it properly as well as figure out what I need to do for id not to be greyed out. At least those are my first focuses.

  **Your code so far**

// Setup
var 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 (prop !== 'tracks' && value !== '') {
  recordCollection.prop(value);
}
else if (prop == 'tracks' && recordCollection.hasOwnProperty('tracks') == false)
{
  recordCollection["tracks"] = [value];
}
else if (prop == 'tracks' && value != '') {
  recordCollection.tracks.push(value);
}
else if (value == '') {
  delete recordCollection.id.prop;
}
return 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/91.0.4472.164 Safari/537.36

Challenge: Record Collection

Link to the challenge:

Updated formatting:

function updateRecords(records, id, prop, value) {
  if (prop !== 'tracks' && value !== '') {
    recordCollection.prop(value);
  } else if (prop == 'tracks' && recordCollection.hasOwnProperty('tracks') == false) {
    recordCollection["tracks"] = [value];
  } else if (prop == 'tracks' && value != '') {
    recordCollection.tracks.push(value);
  } else if (value == '') {
    delete recordCollection.id.prop;
  }
  return records;
}

You have a few issues:

What would you like this line to do? This is not valid syntax

Why not also check if the value is an empty string here?

You cannot use dot notation with variables.

Edit: Also, like @ilenia said, you cannot use recordCollection. You must use the function argument records.

two things
use function parameters, not global variables
and review again how to use variables to access object properties

You are not going that bad, you just need to fine tune a few things

2 Likes

Thank you for saying that! I will review that and try to figure out where I need to go with it. :slight_smile:

You don’t update values inside of an object like that. You can just use a =. Bracket notation is just a different way to get the property (which you need to use here because you can’t use dot notation with variables holding the property names).

Okay I realize now I considered that you could use something like the bracket notation to actually add but you have to use = to modify. I just reviewed that lesson! Thanks for the guidence

1 Like

I wasn’t sure why we use an argument for the records parameter. Since it represents the recordCollection object, and there is only that one object, (not counting the objects within it), why not just use recordCollection without the records argument at all? Like instead of records[id]ect… recordCollection[id]ect… Just curious. :slight_smile:

Sure, there is currently only one object on the screen, but we want our code to be flexible. What if we add rockRecords and popRecords?

that definitely makes sense!

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