FCC JavaScript Course - Record Collection

Tell us what’s happening:
I normally fly through these challenges but for some reason I m really struggling to get my head around this one. Can anyne tell me what I am doing wrong please?
Your code so far


// Setup
var collection = {
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(object, id, prop, value) {
if(object[id][prop] !== "tracks" && !value === "") {
  object[id][prop] = value;}

  else if(object[id].hasOwnProperty("tracks") && !object[id][prop] == "") {
    object[id][prop] = [value];

  }

  else if(object[id].hasOwnProperty("tracks") && !value === "")
  {object[id][prop].push("value")}

  


return object;
}

updateRecords(collection, 5439, 'artist', 'ABBA');
  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

I would double check this

1 Like

First test:

If prop isn’t tracks and value isn’t an empty string,…

Your code:

if(object[id][prop] !== "tracks" && !value === "") {

Should be:

if(prop !== "tracks" && value !== "") {
1 Like

Tell us what’s happening:
Ok, so with the code that you can see below, the first piece (you are going to have to scroll all the way down for the second bit of code), the following challenge milestones are met and not met:

After updateRecords(collection, 5439, "artist", "ABBA") , artist should be the string ABBA

Passed

After updateRecords(collection, 5439, "tracks", "Take a Chance on Me") , tracks should have the string Take a Chance on Me as the last element.

Passed

After updateRecords(collection, 2548, "artist", "") , artist should not be set

Passed

After updateRecords(collection, 1245, "tracks", "Addicted to Love") , tracks should have the string Addicted to Love as the last element.

Failed
After updateRecords(collection, 2468, "tracks", "Free") , tracks should have the string 1999 as the first element.

Failed
After updateRecords(collection, 2548, "tracks", "") , tracks should not be set

Passed

After updateRecords(collection, 1245, "albumTitle", "Riptide") , albumTitle should be the string Riptide

HOWEVER!!

If I change the “!== true” part of my:

  else if(prop === "tracks" && object.hasOwnProperty("tracks") !== true) {
    object[id][prop] = [value];

statement, to just:

  else if(prop === "tracks" && object.hasOwnProperty("tracks")) {
    object[id][prop] = [value]; 

then I fail a different set and pass a different set of challenges??
I suppose what I am trying to ask is how can I be half right on both occaisions? I can figure out how to pass this challenge with a bit of trial and error but I feel that I lack an understanding of what is going on…

This is the one that now fails :
After updateRecords(collection, 5439, "tracks", "Take a Chance on Me") , tracks should have the string Take a Chance on Me as the last element

Thank you in advance to anyone who answers. All the best :smiley:

  **Your code so far**

// Setup
var collection = {
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(object, id, prop, value) {
if(prop !== "tracks" && value !== "") {
  object[id][prop] = value;
}

else if(prop === "tracks" && object.hasOwnProperty("tracks") !== true) {
  object[id][prop] = [value];

}

else if(prop === "tracks" && value !== "") {
  object[id][prop].push(value);
}

else if(value === "") {
  delete object[id][prop];
}
return object;
}

updateRecords(collection, 5439, 'artist', 'ABBA');
  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

check the difference between these two

are you sure that is object that can have a tracks property?

Sorry for the duplicate, I was trying to replace the first one because I went back through the challenges as I was struggling quite a bit with the last challenge in the basic JS course.
Can I delete the first one all together and just keep the new one? I can’t see where to delete the top post?

Also, can you see why that is happening in the new post? With the different milestones being met?

Thanks, David.

I merged the two topics and answered based on your last code, we don’t support deleting topics as a way to circumvent the no duplicate topics policy

1 Like

the dfference between which tests you fail is on this, if you have it like this, the if statement execute when this returns true, if you compare it with !== true then the if statement execute when hasOwnProperty returns false

why neither work? see my previous post

1 Like

ahhhh right, its because I didn’t select the track prop correctly

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