it looks like this is the only line where you use push
you have these two else if, do you think the second one is ever going to run? if prop === 'tracks' && value !== '' is true the first condition is true and the second one is not checked, if it’s false then also the second one is false
I see, so I should swap the order in which these are run? That way it gives the last statement a chance to validate? I’ll give that a shot and see if it works.
Well I’ve come at the problem from a different angle. I am using the undefined operator to validate the statement. The console logs what the message is looking for but it still is not passing the test. See current code below.
function updateRecords(records, id, prop, value) {
if (value === '') {
delete records[id][prop]
}
else if (prop !== "tracks" && value !== '') {
records[id][prop] = value
}
else if (prop === "tracks" && value !== '' && records[id][prop] === undefined) {
records[id][prop] = value
}
else if (prop === "tracks" && value !== "") {
records[id][prop].push(value)
}
return records
}
console.log(updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"))
Here is what is logged in the console after attempting to validate message 3.
// tests completed
// console output
{ '1245': { artist: 'Robert Palmer', tracks: [] },
'2468':
{ albumTitle: '1999',
artist: 'Prince',
tracks: [ '1999', 'Little Red Corvette' ] },
'2548':
{ albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: [ 'Let It Rock', 'You Give Love a Bad Name' ] },
'5439': { albumTitle: 'ABBA Gold', tracks: 'Take a Chance on Me' } }