Tell us what’s happening:
Hi everyone, I am currently in this challenge, but it doesn’t resolve the test
“After updateRecords(2468, "tracks", "Free")
, tracks
should have "1999"
as the first element.”
I can see why other code to solve the problem works, but idk why mine doesn’t, can you explain me please?
Your code so far
// 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"
}
};
// Only change code below this line
function updateRecords(id, prop, value) {
if(prop!="tracks" && value!=""){
collection[id][prop]=value;
}
if(prop=="tracks"&& collection.hasOwnProperty("tracks")==false){
collection[id]["tracks"]=[];
collection[id]["tracks"].unshift(value);
}
if(prop=="tracks" && value!=""){
collection[id]["tracks"].push(value);
}
if(value==""){
delete collection[id][prop];
}
return collection;
}
console.log(collection);
updateRecords(5439, "artist", "ABBA");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0
.
Challenge: Record Collection
Link to the challenge: