Basic JavaScript - Record Collection in Legacy Javascript

Tell us what’s happening:

Describe your issue in detail here.

Your code so far

My code did not pass the test even though it should be working fine I even used copilot to check the issue which told me that code logic is ok

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

Challenge Information:

Basic JavaScript - Record Collection

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Tell us what’s happening:

Describe your issue in detail here.

My code did not pass the test even though it should be working fine I even used copilot to check the issue which told me that code logic is ok

Your code so far

My code did not pass the test even though it should be working fine I even used copilot to check the issue which told me that code logic is ok

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

Challenge Information:

Basic JavaScript - Record Collection

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Hi @zaabdulq

Here is why your code is not passing the tests.

  • If value is an empty string, delete the given prop property from the album.

EDIT

updateRecords(recordCollection, 2548, 'tracks', '');

console.log:

After updateRecords(recordCollection, 2548, "artist", ""), artist should not be set
After updateRecords(recordCollection, 2548, "tracks", ""), tracks should not be set

‘1245’: { artist: ‘Robert Palmer’, tracks: [] },
‘2468’: { albumTitle: ‘1999’, artist: ‘Prince’, tracks: [ ‘1999’, ‘Little Red Corvette’ ] },
‘5439’: { albumTitle: ‘ABBA Gold’ }

Happy coding

Hello @zaabdulq !

Here is a link to great guidance and help with this JavaScript Lesson.

Maybe you can compare your code with it to find the issue in the code.

Smooth coding!

this is not an empty string tho

what are you deleting here?

I am deleting prop which is records[id] since the value is equal to empty string

Oh I GOT IT .The records[id] is a list properties under id not a single property so I should a prop to it to specify it hence record[id][prop]

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