Build a Record Collection - Build a Record Collection

Tell us what’s happening:

failing 2,5,6,8 however result of every step shows correct.

Your code so far

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

function updateRecords(records,id,prop,value)
{ 
  
if(value=="")
{
  delete records[id][prop];
  return records[id];
}
 if((prop!==`tracks`) && (value!==""))
{
    records[id][prop]=value;
  return records[id];
}
if((prop==`tracks`) && (value!="") && (records.hasOwnProperty("tracks")==false))
      {  
       records[id][prop]=[value];
        return records[id];
      }
if ((prop==`tracks`) && (value!=""))
{
  records[id][prop].push(value);
  return records[id];
}
}  
console.log(updateRecords(recordCollection, 5439, "artist", "ABBA"));

console.log(updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"));

console.log(updateRecords(recordCollection, 2548, "artist", ""));

console.log(updateRecords(recordCollection, 1245, "tracks", "Addicted to Love"));

console.log(updateRecords(recordCollection, 2468, "tracks", "Free"));

console.log(updateRecords(recordCollection, 2548, "tracks", ""));

console.log(updateRecords(recordCollection, 1245, "albumTitle", "Riptide"));

Your browser information:

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

Challenge Information:

Build a Record Collection - Build a Record Collection

Double-check this line, please.

was checking this and if ii remove brackets from value it wud start showing error on 3rd step then , with brackets im passing 3rd. It cud be that track is an array so its making me to add brackets.

Your function must always return the entire records object.

Does your code meet this requirement?

yes e.g first function call output:

{ albumTitle: 'ABBA Gold', artist: 'ABBA' }

can see have error on every step where it need to return string as value.

You should only return the collection once at the end of the function.

tried to return all at end issue still there same

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

function updateRecords(records,id,prop,value)
{ 
  
if(value=="")
{
  delete records[id][prop];
  //return records[id];
}
 if((prop!==`tracks`) && (value!==""))
{
    records[id][prop]= value;
  //return records[id];
}
if((prop==`tracks`) && (value!="") && (records.hasOwnProperty("tracks")==false))
      {  
       records[id][prop]= [value];
        //return records[id];
      }
if ((prop==`tracks`) && (value!==""))
{
  records[id][prop].push(value);
  //return records[id];
}
return records[id];
}  
console.log(updateRecords(recordCollection, 5439, "artist", "ABBA"));

console.log(updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"));

console.log(updateRecords(recordCollection, 2548, "artist", ""));

console.log(updateRecords(recordCollection, 1245, "tracks", "Addicted to Love"));

console.log(updateRecords(recordCollection, 2468, "tracks", "Free"));

console.log(updateRecords(recordCollection, 2548, "tracks", ""));

console.log(updateRecords(recordCollection, 1245, "albumTitle", "Riptide"));

This is not returning the entire collection.

updated it to : return records; and now error on step

// running tests
3. After updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"), tracks should have the string Take a Chance on Me as the last and only element.
6. After updateRecords(recordCollection, 2468, "tracks", "Free"), tracks should have the string 1999 as the first element.

Here are some debugging steps you can follow. Focus on one test at a time:

  1. Are there any errors or messages in the console?
  2. What is the requirement of the failing test?
  3. Check the related User Story and ensure it’s followed precisely.
  4. What line of code implements this?
  5. What is the result of the code and does it match the requirement? (Write the value of a variable to the console at that point in the code if needed.)

If this does not help you solve the problem, please reply with answers to these questions.

checked all and I believe records[id][prop].push(value); this not working properly as result comes as :

{ albumTitle: '1999',
     artist: 'Prince',
     tracks: [ 'Free', 'Free' ] },

original object is :
 2468: {
    albumTitle: '1999',
    artist: 'Prince',
    tracks: ['1999', 'Little Red Corvette']

so it shuld add value at end ?

requirement: After updateRecords(recordCollection, 2468, “tracks”, “Free”), tracks should have the string 1999 as the first element.

have problem in this part as it keep adding value to array twice

if((prop==`tracks`) && (value!="") && (!records[id].hasOwnProperty("tracks")))
      {  
      records[id][prop] = [];
      records[id][prop]=[value];

      }

output :
'5439': 
   { albumTitle: 'ABBA Gold',
     tracks: [ 'Take a Chance on Me', 'Take a Chance on Me' ] } }

its not passing have tried everything.
1 Like

full code:

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

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

      }
if ((prop==`tracks`) && (value!=="")&& (records[id].hasOwnProperty("tracks")))
{
  records[id][prop].push(value);
  
}
return records;
}  
//console.log(updateRecords(recordCollection, 5439, "artist", "ABBA"));

console.log(updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"));


//console.log(updateRecords(recordCollection, 2548, "artist", ""));

//console.log(updateRecords(recordCollection, 1245, "tracks", "Addicted to Love"));

//console.log(updateRecords(recordCollection, 2468, "tracks", "Free"));

//console.log(updateRecords(recordCollection, 2548, "tracks", ""));

//console.log(updateRecords(recordCollection, 1245, "albumTitle", "Riptide"));

found the error thanks for help:)