Basic JavaScript - Record Collection

Tell us what’s happening:
Describe your issue in detail here.

  **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 !== 'tracks' && value !== "") {
  records[id][prop] = value
} else if (prop === 'tracks' && records[id].hasOwnProperty('tracks') === false) {
  records[id][prop] = [value]
} else if (prop === 'tracks' && value !== "") {
  records[id][prop].push(value)
} else if (value === "") {
  delete records[id][prop]
} 
return records;
}

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

console.log(records);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

Hi,

I’m completely stuck on why it’s showing “ReferenceError: records is not defined”.

Any help will be greatly appreciated. Starting to bleed out of my ears lol.

Thanks in advance!

This console.log has no idea what records is.

In this case records makes sense only for the function, because it’s one of the parameters

Outside of function it’s nothing

1 Like

Hi! Hopefully I can help some too, I’ve been really stuck on this as well. So, do you see how in the function updateRecords, there’s a parameter that says ‘records’? I didn’t realize this, but when you call on a function to be performed, you can set up new variables and constants there. So, when you’re calling on ‘records’, it can’t really call on much of anything because… ‘records’ got defined in that specific function as a parameter, but it doesn’t really mean much else to JavaScript outside of that. Does that make some sense?

So, you should actually be calling on the console to log recordCollection because it’s inside that constant you modified data with your new function. Records can’t exist on it’s own, but it exists as a parameter/variable housed inside updateRecords, and if you compare the updateRecords example with the function updateRecords, you can see it’s one to one! recordCollection is to ‘records’. I think of it like a ratio or something standing in to represent something else.

I just understood this this morning and I wanted to share some guidance. Hope that helped! Good luck!

1 Like

Felt like I spent 3 hours trying to push a square through a round hole and willing it to fit :laughing: thanks :handshake:

omg that makes perfect sense now! thanks so much for the explanation, I had been staring at the screen so long that not even my name was making sense by that point :laughing:

thanks again you’re a life saver :handshake:

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