Basic JavaScript - Record Collection

Hello guys I really cant understand this problem. Can someone please explain to me the last step where in the code we have to write
if (records[id].hasOwnProperty("tracks")===false) { records[id][prop] = [];
I understand everything else except this part
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 (value === "") {
    delete records[id][prop];
  } else if (prop!== "tracks" && value !== ""){
     records[id][prop] = value;
  }else if (prop==="tracks" && value !==""){
    if (records[id].hasOwnProperty("tracks")===false) {
       records[id][prop] = [];
  return records;

console.log(updateRecords(recordCollection, 5439, 'artist', 'ABBA'));

Your browser information:

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

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

Why did you write it though?

The instructions on this Challenge are supposed to be written in a way that you can translate them to code, so that bit you highlighted should correspond to a sentence in the instructions.

1 Like

I checked a youtube tutorial on how to solve this and the solution and this was the answer for that line.

Ah. Simply having the answer is pretty useless. The point of this challenge is figuring out how convert the instructions to code.

I’d look at the bullet points in the instructions and try to match that code back up to one of the sentences there.

yes I know but I’ve been stuck on this for hours so figured I would check the answer…
It says
If prop is tracks and value isn't an empty string, you need to update the album's tracks array. First, if the album does not have a tracks property, assign it an empty array.
I think that understand that i use this (records[id].hasOwnProperty("tracks")===false) { records[id][prop] = [];
to check if the album name has the same value as tracks and if it is false it gives it a new name that is blank.
Is that correct?

I’d definitely talk to other humans about the problem before you spin your wheels for hours.

That’s pretty close. I’d be careful with what you mean by ‘if the album name’ though. We are talking about the album tracks here.

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