The dreaded Records Collection assignment. Am I on the right track?

Tell us what’s happening:
So I am on the infamous Record Collection assignment. My code is obviously broken and disgusting, but I am just wondering if my general foundation seems close. The code does not run, so I don’t really know which of it is correct, and which of it is not. I am struggling with this part:

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

I am not sure how to write code to identify if the album has a tracks property or not.

But does my overall logic seem sound? Am I on the right track? If I am wayyyyyy out to lunch I will clear and start over.
Thanks!

  **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 prop != recordCollection.id.tracks && value != "" {
  prop = value;  // I think this part is right
} else if prop == recordCollection.id.tracks && album __________ {  
// ^^ not sure how to say "doesn't have a tracks property" FIX THIS
  let emptyArray = [value];  // Am I supped to create a new array?
} else if prop == tracks && value != "" {
  tracks.push([value]);  // I think this part is right
} else if value == "" {
  delete.prop; // I think this part is right
}
return records;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');
console.log(recordCollection);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0

Challenge: Record Collection

Link to the challenge:

You have forgotten the () around all of the conditions of your if statements.

1 Like

You are on the right track.
Couple of corrections though:

  1. When you compare values - try to verify you know what you are comparing against what. Take a look at how you deal with tracks for example and think what it would compare versus what you would want it to compare.
  2. As for the comparison against not - remember every conditonal can be reversed. Say you are comparing against a value being equal:
if (price === 10) {}

when you want to do the opposite you can negate the condition

if (price !== 10) {}
  1. You are asking the correct question

Especially this part. Replace the word album, with a more generic programming related word for this data structure, and look in MDM / google - you will get immediate hits!

1 Like

Thanks that is handy information. I know my dog-puke code is full of syntax errors, but I have been sorta banging out rough code (syntax errors or not) just to get a foundation down. Then I go over it and try to clean it up. I will try to narrow in on what you said. and hopefully I can improve this. Thanks so much again.

Note that you can’t access properties with dot notation when the property names are stored in variables. Dot notation is only for the exact literal name of the property.

Prop is just a string. You shouldn’t be changing this string, you should be updating the records.

You cannot reference the global variable. That breaks your function by hardcoding it to only work with a single records collection.

Again, you should be changing the records.

Same thing here

And here… Also you don’t use delete like that

Strict equality with === is preferred over ==

Oh boy… thanks for that. I didn’t realize it was so bad until now. You really opened my eyes these past few days about how poorly I am comprehending JS in general. (Despite me restarting the FCC JS curriculum twice, and taking notes, and keeping another browser open just to access previous topics)… I am a very bad learner and it has been a life-long frustration for me. (I am 41).

I have been on this for 6 hours today, (and all night until 2am yesterday) and even with all the great advice, I am just not ready for this assignment. I need to back down and re-visit some of the more basic JS concepts.

So I think I am going to bookmark this page, and try taking a Lynda or Udemy course first, then come back and take another crack in the near future using the advice you guys gave me. That might be a better course of action vs me constantly asking questions that I should understand by now.

This all reminds me of highschool math back in the 90’s. Haha.

You have a lot of the correct ideas here. It’s mostly bad syntax fighting you.

Instead of starting with code that doesn’t run and adding more to it, for problems like this I recommend starting with a buch of comments describing your plan and then slowly building up code that accomplishes pieces of the plan. That way you have code that runs and can be experimentud with most of the time.

1 Like

Please open your own thread instead of hyjacking an old thread. Thanks!

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