Hi
I am almost done with this challenge, except that when the test code is:
updateRecords(5439, “artist”, “ABBA”);
my solution reads:
“artist”: [“ABBA”]
which is not recognized as solved.
If I don’t add the artist:ABBA to an empty array, I pass this test, but not others.
which is not recognized as solved.
Any suggestions?
Thanks.
also I am not sure what is the proper way to show my solution so far
Please share your code and tell us what the failing test says.
// 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
var collectionCopy = JSON.parse(JSON.stringify(collection));
// Only change code below this line
function updateRecords(id, prop, value) {
var object = collection[id];
if(value){
if(!object.hasOwnProperty(prop)){
object[prop] = [];
}
object[prop].push(value);
// if (object[prop].length==1){
// object[prop] = object[prop].toString();
// }
}
else{
delete object[prop];
}
return collection;
}
// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
I don’t pass this test
After updateRecords(5439, “artist”, “ABBA”), artist should be “ABBA”
(I pass all other tests)
my solution shows:
‘5439’: { album: ‘ABBA Gold’, artist: [ ‘ABBA’ ] }
if I don’t put this value inside an array, I pass this test
(‘5439’: { album: ‘ABBA Gold’, artist: ‘ABBA’ }
I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.
artist
should be a string, not an array.
"ABBA"
is not the same thing as ["ABBA"]
yes, I see the difference. What was not clear to me was that only for tracks key I should create a new, empty array. So for the artist key, I will add the value as string.
Thank you for clarifying this. (and for your help with formatting)
I just did this change, and it works. thanks again