Help w record collection challenge

hi everyone! i’m stuck in the record collection challenge from the basic javascript challenges. i was looking the solutions made by other users but i still don’t know how to set the new properties for the record, the modifications that the challenge is asking for. i’ve configured (with SOME help) this code for the first part, when we have to follow the rules like “if prop is an empty string…” and so on.

function updateRecords(object, id, prop, value) {
if (prop !== 'tracks' && value !== "") {
 object[id][prop] = value;
}
else if (prop === 'tracks' && !object[id].hasOwnProperty("tracks")) {
  object[id][prop] = [value];
  }
  else if (prop === tracks && value !== "") {
object[id][prop].push(value);
}
else if (value === "") {
  delete object[id][prop];
  }
  return object;
}

BUT i can’t find help about the second part, like, p.e. "After updateRecords(collection, 5439, "artist", "ABBA") , artist should be ABBA"

I’ve tried to code this using my intuition (?, but obviously it doesn’t work since I don’t know exactly what is the syntax i should use

updateRecords(collection, 5439, ‘artist’, ‘ABBA’); // This line is previously offered as an example, but I don’t understand if the other modifications should respect the same structure, since it doesn’t work

updateRecords(collection, 5439, 'tracks'.push(["Take a Chance on Me"]);
updateRecords(collection, 2548, 'artist' = "");
updateRecords(collection, 1245, 'tracks', collection.tracks.push(["Addicted to Love"]);
updateRecords(collection, 2468, 'tracks'.unshift([1999]);
updateRecords(collection, 2548, 'tracks' = "");
updateRecords (collection, 1245, 'albumTitle' = 'Riptide');

I appreciate any help or suggestions, I am a little lost code-beginner. xoxo

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.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

In such situations it’s usually good idea to take a look at the not passing tests and try to figure out what exactly is happening with them. Is function simply not doing what is expected, or if there’s some kind of error that stops function from executing?

Remove or comment other function calls from the bottom of code and add there code calling non-passing test, just copy the updateRecords(...) from the left. As function is
always returning modified collection object, you can wrap the call with console.log(), so the resulting object will be shown in console and it will be easier to check if changes are as they should.

1 Like

this will give an error, you can’t assign a string to a string

also 1st and 4th, error, you can’t use an array method on a string

also the various others have arguments that do not match the algorithm logic: the third argument should be a string

1 Like