Tell us what’s happening:
Hi all. I’ve been trying for a solution and I don’t find a logical error (maybe there is). Is it that or some special character I missed? I don’t expect a solution, just a hint at what I may be doing wrongly. Thanks.
Your code so far
// Setup
var collection = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
2468: {
albumTitle: '1999',
artist: 'Prince',
tracks: ['1999', 'Little Red Corvette']
},
1245: {
artist: 'Robert Palmer',
tracks: []
},
5439: {
albumTitle: 'ABBA Gold'
}
};
// Only change code below this line
function updateRecords(object, id, prop, value) {
if (prop != "tracks");
value === [id][prop] }
if (value === "tracks");
tracks[value]; {
} if
(value === '') delete [id][prop],
return object;
}
updateRecords(collection, 5439, 'artist', 'ABBA');
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36.
@jenovs and @ilenia I’m sorry for my bad syntax.
Thank you for taking the time to answer.
I read the solution but I wanted to try it with code of my own. Problem is there are things I should already know but I’m a slow learner.
I know that.
So forgive me for my bad code. I thought nobody would answer and you did.
The same happened to me with css flexbox but you should see my code now. Because someone cared enough to help me. Like you both are doing now.
I promise I will improve. And thank you again.
I’m having too many structural doubts and before I keep on with this challenge I’m going to re-read the curriculum or at least certain points of it, like you said, objects especially. I just thought I was really close to solve this challenge but I’m clearly not. So thank you. I’ll keep on studying and may I go on coding and do something that makes sense. Thank you.
Hi, I think I understand better now. I did the reasoning and took some pieces of code from other places, but mostly I did on my own. I got problems with the .push property it seems. Can you help? Thank you,
function updateRecords(object, id, prop, value) {
if (prop !== 'tracks' && value !== '') {
collection[id][prop] = value;
} else if (prop == 'tracks' && 'tracks' === undefined) {
collection[id][prop] = [];
} else if (prop == 'tracks' && value != '') {
collection[id][prop]['tracks'].push(value);
} else {
(value == '')
delete collection[id][prop];
}
return object;
}
updateRecords(collection, 5439, 'artist', 'ABBA');
@RandellDawson thank you, I’ll take care of that. @RandellDawson still doesn’t check out.
I studied objects last night and I understand the challenges, then come here and feel at a loss. @ilenia you said I could bother again I think the fail is in the push line. Not sure how to solve it yet.
I got better at the syntax though. At least is something.
@JeremyLT Jeremy, it’s the most understanding comment I have received.
Many times I’ve said to myself I shouldn’t go on with this if there are so many concepts I can’t handle.
But something tells me I should follow.
Thank you for your sympathetic (and useful) reply.
After spending 5 hours trying to fix this code, do it first on paper as @JeremyLT recommended I’ve finally come to this. I understood the “official” solution, it makes perfect sense, but I’m stubborn and wanted to do it myself because that’s the way you learn. Trying and failing. But I had a ton or errors and finally I only have one which makes me think it must be something very little that’s why I come to you for help. I think the logical errors are solved and hope not to be wrong here.
I posted the code in an image so you see the single error it generated. Then I copy it in code text.
// Only change code below this line
function updateRecords(object, id, prop, value) {
if (prop !== "tracks" && value !== "") {
object[id][prop] = value;
}
if (prop === "tracks" && "tracks" === []) {
object[id][prop] = [];
[] = value;
}
if (prop === "tracks" && value !== "") {
object[id][prop].push(value);
}
if
(value === "") {
delete object[id][prop];
}
return object;
}
updateRecords(collection, 5439, 'artist', 'ABBA');
@JeremyLT Thank you Jeremy, I passed the test! I had to set “tracks” as the array and give the value of undefined.
You surely must guess how good I feel now.