Basic JavaScript: Record Collection - promble

this my code, i don’t know why i can’t pass this :’(
please help me~~~
thank you!!

// 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(object[id][prop] !== 'tracks' && value !== ""){
    object[id][prop] = value
  }else if(object[id][prop] === 'tracks' && object[id][prop].hasOwnProperty === flase ){
    let tracks = []
    object[id][prop] = value
  }else if(object[id][prop] === 'tracks' && value !== ''){
    object[id][tracks].push(value)
  }else if(value === ''){
    delete object[id][prop]
  }
  return object;
}

updateRecords(collection, 5439, 'artist', 'ABBA');

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

Here, you aren’t using the hasOwnProperty method correctly. I’d Google the documentation to check how that method works.

Also, you probably want to check that the value is not an empty string in that conditional.

I don’t think this does what you think. You want the end result of this if clause to be that object[id]["tracks"] is an array with a single value.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.