Basic JavaScript - Record Collection

Tell us what’s happening:
While I was manually going through the various tests, they all worked for me, but the auto tests said they were all wrong aside from the 5th test. I am curious to why this is because when I went through my code line-by-line, it looked correct to me.

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) {
  if(value == "") {
    delete recordCollection[id][prop];
    return records;
  } else {
    if(prop != "tracks") {
      recordCollection[id][prop] = value;
    } else { // if prop is tracks
      if(recordCollection[id].tracks) { // if tracks is set
        recordCollection[id][prop].push(value); // add val to last item of array
      } else { // if tracks is not set, create array
        recordCollection[id].tracks = [value];
      }
    }
    return records;
  }
}

// updateRecords(recordCollection, 2548, "artist", "");
updateRecords(recordCollection, 1245, "tracks", "Addicted to Love");

console.log(recordCollection);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

You should be using the records parameter, not the top-level recordCollection. It is passed to the function as an argument.

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