Basic JavaScript - Record Collection

Tell us what’s happening:
I’ve been working on the Record Collection problem for a while and looking through the forums and examples of solutions and I can’t figure out why my code is only not passing the test where you have to create the new array for the Abba album and then input the new value into the array. I am creating the new array and using .push( ) to add the value to it but it does nothing. Any wisdom as to what I am doing wrong?

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

updateRecords(recordCollection, 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/ Safari/537.36

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

I think these two together aren’t quite working right? What do you want these two to do?

The first code block is for if the input property is “tracks” and the value is not an empty string to add the value to the property tracks and the second is if the input property is tracks, but there is not a property already created for tracks to create one and then add a value to it.

I see what you’re saying because the second block of code isn’t even being run because the first block of code meets the criteria of the second block. Maybe I need to swap them or figure out a different solution.

Bingo. There are a few ways to fix this. You can combine the blocks or change the order of the blocks.

1 Like

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