Hi all, Having some probs getting this to work, UGH!
I know there might be more than one solution to solving this and there is a ‘preferred’ solution as well.
-
Any advice on how to more efficiently look at the directions and decide what steps should be solved first and which last. The order of things. I’ve been over this several times diff ways, but seem to keep getting some logic wrong with the approach.
Maybe it would help enlighten others (with no strong programming background) to know how to look at the logic approach and understand how to tell what steps in the word problem should be solved first, etc. -
Here is my last approach. Could anyone help me understand why this wouldn’t be working as well.
I seem to keep getting stuck and can’t figure out if it is because i’m doing the steps in the wrong order or if it is just a programming mistake.
Thanks in advance,
FYI, I try not to spend too much time trying to solve things. I don’t like wasting days on something I can’t figure out.
// 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 value is ""
if (value === "") {
delete collection[id][prop];
// If prop is NOT 'tracks' && value is NOT "", than set the value
} else if (prop != "tracks" && value != "") {
collection[id][prop] = [value];
// If prop IS 'tracks' && .hasOwnProperty('tracks') IS false
} else if (prop === "tracks" && collection.hasOwnProperty("tracks") === false) {
collection[id] = [prop];
// If prop IS tracks && value is NOT ""
} else if (prop === "tracks" && value != "") {
collection.id.prop.push(value);
}
return collection;
}
// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");