Basic JavaScript - Record Collection

Tell us what’s happening:
Describe your issue in detail here.

PLEASE HELP :sweat_smile:, I cannot get through this challenge to save my life-

Record Collection

You are given an object literal representing a part of your musical album collection. Each album has a unique id number as its key and several other properties. Not all albums have complete information.

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.

Note: A copy of the recordCollection object is used for the tests
Your code so far

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

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Safari/605.1.15

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

I don’t think you are off to a good start here. I would lose this completely.

1 Like

Thanks a lot for the help. I originally didn’t have this, but I saw it in the “hint” directions.

Also, you should only have one return statement in this function. The one at the end.

1 Like

You have other issues as well. I didn’t point them all out because I’m hoping as you make this particular change that you will figure out the others. But if you are still stuck then paste your updated code in here.

To display your code in here you need to wrap it in triple back ticks. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key. You may also be able to use Ctrl+e to automatically give you the triple back ticks while you are typing in the this editor and the cursor is on a line by itself. Alternatively, with the cursor on a line by itself, you can use the </> button above the editor to add the triple back ticks.

function updateRecords(records, id, prop, value) {
  if (prop !== "tracks" && value !== "") {
      records[id][prop] == value;
  } else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === false) {
      records[id][prop] = [value];
  } else if (prop === "tracks" && value !== "") {
      records[id][prop].push(value);
  } else (value === "") 
    delete records[id][prop];
  
  return records;
}

Do you want to do a boolean comparison here or assign a value?

I want to assign a value. Sooo, I should get rid of the double ==?

I’m not going to give you the answer to that question. I think you already know the answer :slight_smile: Because in the next block you assigned a value properly.

P.S. You still have one more error after this one. An else by itself doesn’t use a conditional statement to determine if it should do anything. An else by itself always does something.

Roger that. With the advice I got from you guys and a few YouTube videos, I figured out what the problem was and solved the challenge.

I still have to review and master the basics.

Anyway thanks for taking the time to help, much appreciated.

function updateRecords(records, id, prop, value) {
  if (prop !== "tracks" && value !== "") {
      records[id][prop] = value;
  } else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === false) {
      records[id][prop] = [value];
  } else if (prop === "tracks" && value !== "") {
      records[id][prop].push(value);
  } else if (value === "") 
    delete records[id][prop];
  
  return records;
}

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