I am not sure what I am missing on this challenge. It states I am not passing 3 test, but when I run it in my web console, the 1st 2 display the expected results…only the 3rd line is not correct.
Here is the failing test results:
After updateRecords(5439, "tracks", "Take a Chance on Me"), tracks should have "Take a Chance on Me" as the last element.
After updateRecords(1245, "tracks", "Addicted to Love"), tracks should have "Addicted to Love" as the last element.
After updateRecords(2468, "tracks", "Free"), tracks should have "1999" as the first element.
Here is my code:
function updateRecords(id, prop, value) {
//if value is empty
if(value === "") {
// delete property
delete collection[id][prop];
}
// If prop is "tracks"
else if (collection[id][prop] === "tracks") {
//the album have a "tracks" property
if(collection[id].hasOwnProperty("tracks")) {
// push the value onto the end of the album's existing tracks array
collection[id][tracks].push(value)
}
else {
//create an empty array
collection[i][tracks] = [];
//before adding the new value to the album's corresponding property
collection[i][tracks].push(value);
}
}
else {
//update or set property of album
collection[id][prop] = value;
}
return collection;
}
// Alter values below to test your code
console.log(updateRecords(5439,"tracks","Take a Chance on Me"));
console.log(updateRecords(1245,"tracks","Addicted to Love"));
console.log(updateRecords(2468,"tracks","Free"));
Any help is greatly appreciated. Thank you.