Record Sellection Question

Tell us what’s happening:

I am just not sure where I am going wrong here

Your code so far


// 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'
}
};

var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

if(value === "") {
delete collection[id][prop];
} else if (prop === "tracks") {
collection[id][prop] = collection[id][prop] || [];
} else {
collection[id][prop] = value;
}

return collection;
}
updateRecords(2468, "tracks", "test");
console.log(updateRecords(5439, 'artist', 'ABBA'));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

The object literal notation is not the same as the J ava S cript O bject Notation (JSON). Although they look similar, there are differences between them:

JSON permits only property definition using “property”: value syntax. The property name must be double-quoted, and the definition cannot be a shorthand.

var collection = {
  2548: {
    albumTitle: 'Slippery When Wet',
    artist: 'Bon Jovi',
    tracks: ['Let It Rock', 'You Give Love a Bad Name']
  },

Qbviously “collection” must be an object literal, literally an Object.
You are expected to pass this Object to the function as the first argument.
updateRecords(collection, 5439, ‘artist’, ‘ABBA’);

function updateRecords(object, id, prop, value) { …

1 Like

Hello!

The lesson has recently been updated but the video has not, hence if you try to use the video’s solution it will fail. Instead, try what @Da_vey says or use the Hint.

This is the new default code:

// 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) {
  return object;
}

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

With that said, not modify anything other than the body of the updateRecords function:

function updateRecords(object, id, prop, value) {
  // Add your code between this comment and...

  // ...this comment
  return object;
}