Basic Javascript - Record Collection

So, what am I missing here? There is an example that showed me how to update the collection, so I went ahead and did that. But nothing changes. Even the example properly updated ‘Abba’, but that particular requirement did not pass for some reason.

Challenge:

// Setup
const recordCollection = {
  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(records, id, prop, value) {
  return records;
}

updateRecords(recordCollection, 5439, "artist", "ABBA");
updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me");
updateRecords(recordCollection, 2548, "artist", "");
updateRecords(recordCollection, 1245, "tracks", "Addicted to Love");
updateRecords(recordCollection, 2468, "tracks", "Free");
updateRecords(recordCollection, 2548, "tracks", "");
updateRecords(recordCollection, 1245, "albumTitle", "Riptide");

It really helps if you post the link to the challenge.


I’ve edited your code 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 haven’t added anything to this function yet.

I added the data to the function but it doesn’t seem to help as well.

Did you add anything to the function? You should not make any changes to the data structure - only to the function.

The function needs to have the logic for updating the data structure.

The challenge is asking you to create a function that creates or update the record collection, in the code you shared above I can’t see the function you created.

/ Only change code below this line
function updateRecords(records, id, prop, value) {
updateRecords(recordCollection, 5439, "artist", "ABBA");
updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me");
updateRecords(recordCollection, 2548, "artist", "");
updateRecords(recordCollection, 1245, "tracks", "Addicted to Love");
updateRecords(recordCollection, 2468, "tracks", "Free");
updateRecords(recordCollection, 2548, "tracks", "");
updateRecords(recordCollection, 1245, "albumTitle", "Riptide");
  return records;
}

I’ve changed it to this

How much Javascript do you know?

That will create an infinite recursion.

This is not what you’ve been asked in this challenge, what you typed in here is just the different scenarios where the function you’ll write will do it’s job. Check the challenge requirements and try again.

Not much more than the Javascript taught so far in the course. In all fairness I was working on picking items from nested arrays which all sounded feasible and perfectly understandable and all of a sudden the next assignment turns to this. The example provided by the course creator with ‘abba’ being placed as artist so far made perfect sense but for some reason none of the requirements seem to ‘tick’.

Read this part carefully. Ask questions about the pieces that don’t make sense:

You start with an updateRecords function that takes an object literal, records, containing the musical album 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 record collection 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.

Can you answer

  • What is records?
  • What is id?
  • What is prop?
  • What is value?

Records = record collection
id = the four digit number resembling the album
prop = property of the album such as albumTitle, artist and tracks
value = value of said property

Ok, reset the code start with one bullet point at a time.

How do you do the first bullet point?

How do you do the second bullet point?

  • return recordCollection;

  • if prop != “tracks” {
    Records.prop = “value”;
    } else if prop != “ “ {
    Records.prop = “value”;

  • I wouldn’t know unfortunately how to do bulletpoints 3 and 4

  • if value = “” {
    delete Records.prop;
    }

There is no recordCollection inside of the object.

This will be easier if you post full code instead of pesudocode.

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