FREECODECAMP ->ADVANCE ALGORITHM SCRIPTING->Record Collection bug? [SOLVED]

FREECODECAMP ->ADVANCE ALGORITHM SCRIPTING->Record Collection bug? [SOLVED]
0.0 0

#1

as you can see in the image, i added “FREE” to “Tracks” array, and “1999” is the first element at the same array, so i don’t understand the error it gives me


#2

Can you post your code (not a screenshot, but the code itself)? :slight_smile:


#3
          // Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
 "artist": "Robert Palmer",
 "tracks": [ ] 
 },
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
// Only change code below this line
 function updateRecords(id, prop, value) {
 console.log(Boolean(value));
 if (prop=="tracks"&& Boolean(value)===true){
 var property = collection[id][prop];
 if(Array.isArray(property)) property.push(value);
else {property=[];property.push(value);}
}
else if(!Boolean(value)){
delete collection[id][prop];
 }
  else{
  collection[id][prop]=value;
 }
return collection;
 }
// Alter values below to test your code
 updateRecords(2468, "tracks", "Free");`Preformatted text`

#4

Hmmm… I’m getting different tests wrong. I got the first two tests wrong, and the test in question is green.

I noticed that this line is missing in your code (right before the function declaration):

// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

When I added it back the first test went green.


#5

well, u were right’ for some reason it was stuck on that error for no reason, i had to remove something in the code for the error to update :-/, solved it, thanks