What's wrong with my code? any help?

Tell us what’s happening:

You start with an updateRecords function that takes an object like collection , an id , a prop (like artist or tracks ), and a value . Complete the function using the rules below to modify the object passed to the function.

  • Your function must always return the entire object.
  • If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value .
  • If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.
  • If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array.
  • If value is an empty string, delete the given prop property from the album.

Your code so far

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

/ my code do not work in the final step -“delete the given prop property from the album”.

A link to the challenge would help. You’ve removed it from the format.

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 (’).

You are referencing the global variable collection when you should be referencing the function argument object.

1 Like

Thank you :slight_smile: :slight_smile: I corrected my mistake (object instead of collection) .

1 Like