if (prop !== "tracks" && value !== ""){
object[id][prop] = [value];
}
[value] is different than value. In object[id][prop] you have to use brackets to use the variable, but in the second part you have to assign just the variable otherwise you would be changing the type, in this case the brackets means something else, it would be an array as you can test with the following. Try this:
if (prop !== "tracks" && value !== ""){
object[id][prop] = [value];
console.log(typeof(value));
console.log(typeof([value]));
console.log(value);//string
console.log([value];//array
}
If the property isn’t “tracks” it could be albumTitle or artist, so it just needs the name of the album or artist, just the string not an array, so assign a string to it.
if (prop !== "tracks" && value !== ""){
object[id][prop] = value;
}
So it must be different from the next part. Tracks must be an array so you have value inside brackets: [value]. Which is correct in your code. Which leads us to problem 2: the second condition.
problem two:
so if prop is tracks but the property doesn’t exist you need to create an array with an element value inside. But to check if the property exists you have to rewind a few lessons before Record Collection, in the lesson named Testing objects for properties, which presents the .hasOwnProperty() method. The one you used I believe would be this one? MDN Object.getOwnPropertyNames().
So you would have this instead:
else if (prop === "tracks" && !object[id].hasOwnProperty('tracks')){
object[id][prop] = [value];
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.