Can someone please help?!

Basic JavaScript: Record Collection

Im going crazy here. I tried to solving this in a 10 diffrent ways, I get it now but it still wont pass… Can someone tell me what is wrong here. Im at it since yesterday… Hellp! In console.log removes it but it still wont pass. Thanks in advance!

After updateRecords(collection, 2548, "artist", "") , artist should not be set

After updateRecords(collection, 2548, "tracks", "") , tracks should not be set

// 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 (prop != "tracks" && value != "") {

    collection[id][prop] = value;

  } 

  else if (prop === "tracks" && collection[id][prop] === undefined) {

    collection[id][prop] = [value];

  } 

  else if (value === "") {

   delete collection[id][prop]

  } 

  else if (prop === "tracks") {

    collection[id][prop].push(value);

  } 

  return collection;

}

console.log(JSON.stringify(updateRecords(collection, 2548, "tracks", "")));

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

//console.log(JSON.stringify(collection[5439]));

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

Hi and welcome to the forum.

Your main issue is that you are using collection when you need to be using object.

2 Likes

Brother I LOVE YOU!!!

1 Like