I was hoping someone could clear this up for me (in reference to the answer key for the problem):
Why are quotes around <code>"tracks"</code> required to pass the test? I'm not understanding why they're necessary.
Why is including <code>return</code> after each <code>if else / if</code> statement incorrect? I'll copy and paste my code here just to make it clear what I'm referring to.
// Only change code below this line
function updateRecords(records, id, prop, value) {
if (prop !== "tracks" && value !== "") {
return records[id][prop] = value;
} else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === false) {
return records[id][prop] = [value];
} else if (prop === "tracks" && value !== "") {
return records[id][prop].push(value);
} else if (value === "") {
delete records[id][prop];
}
return records;
}
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
The return statements like that don’t work and you shouldn’t use them in that way.
The assignment operator = has a return value. You can see this by doing
let myVar = 4;
console.log(myVar = 5); // will log the 'return value' of the assignment 'function'
This seems funny, but it lets you do things like
let myFirstVar = 4;
let mySecondVar = 5;
myFirstVar = mySecondVar = 6; // will set both to 6
So in this case, the right hand side of the assignment operator becomes your return value for the entire function.
As far as the quotes go, "tracks" is a string and tracks is an undefined variable. In this challenge, the prop is a string holding the property name, so you need to compare it against a string with the property that you are interested in.