Basic JavaScript - Record Collection

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

Your code so far
I don’t know where to start honestly. This whole thing is entirely confusing. Can someone explain how records is connected to the variable recordCollection? What to do in the 2nd question? " * If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it." What should I do after else if prop == tracks? I seriously do not want to copy and paste everything with 0 comprehension. I want to learn more in detail. Please someone help?

// 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  )
  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/110.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

The function call (the last line) says, in words, "run the function updateRecords with records = recordCollection, id = 5439, prop = 'artist', and value = 'ABBA'.

This doesn’t do what you think. You should see an error in the console. What does that error say?

Oh and can I use dot Notation?

Dot notation only works with the exact literal property name, not a variable holding the property name.

I wrote exactly what the first question asked of me but not sure if I wrote this line correctly “records[id][prop] = value;”. I looked at the hint but never understood how records and recordCollection connect with one another. However, I look at the console and has many errors so not sure what issue could be?

Now I understand how records is equal to recordCollection

Not quite.

This is an error. What type of thing will prop be? A number? A string?

prop has artist and tracks so a string. That means I got put it in quotes?

Give it a try. That sounds like good reasoning to me.

Okay seems like I made a lot errors and not sure where to start. The console marked everything wrong and not understanding what its asking for.

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

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

This part looks ok to me.

This looks like a problem to me.

What sort of thing is id? Is it an object?

Why are you modifying the variable prop? This function needs to update records.

I am not sure what you intend this line to do?

I don’t think your if condition is quite right. Also, you cannot use dot notation when the property name is stored in a variable.

This should not be in an else clause. The records object must always be returned.

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