Build a Record Collection - Build a Record Collection

Tell us what’s happening:

i dont knjow how to complete this exercise,i haqve no idea what to do now

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]
}else if(prop !== 'tracks' && value!== ''){
  records[id][prop] =value
}else if(prop === 'tracks'){
 if(Array.isArray(records[id].tracks === false)){
   records[id].tracks =[]
 }
}if(prop === 'tracks' && value !== ''){
records[id].tracks.push(value)
}

return records
}
console.log(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/138.0.0.0 Safari/537.36

Challenge Information:

Build a Record Collection - Build a Record Collection
https://www.freecodecamp.org/learn/full-stack-developer/lab-record-collection/build-a-record-collection

Can you say more about how you are stuck? What is working? What is now working?

  1. 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.

If you check tracks what is the last (or only) element?

you may want to right click in the editor and click Format document, your if/else if/else is hard to read like this and you may be missing something

when i use:
console.log(updateRecords(recordCollection, 5439, “track”, “Take a Chance on Me”));
it shows the correct output but doesnt pass

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'){
 if(Array.isArray(records[id].tracks === false)){
   records[id].tracks =[]
 }
}if(prop === 'tracks' && value !== ''){
records[id].tracks.push(value)
}

return records
}
console.log(updateRecords(recordCollection, 5439, "artist", "ABBA"))

i formatted it

That still is not formatted. You can tell because the inner content of the function is not indented.

You don’t get the error TypeError: Cannot read properties of undefined (reading 'push') when testing updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me")?

that’s where i need help

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]

  } else if (prop !== 'tracks' && value !== '') {

    records[id][prop] = value
  }
 else if (prop === 'tracks') {

    if (Array.isArray(records[id].tracks === false)) {
      records[id].tracks = []

    }
  } if (prop === 'tracks' && value !== '') {

    records[id].tracks.push(value)
  }

  return records
}
console.log(updateRecords(recordCollection, 5439, "track", "Take a Chance on Me"))




I don’t think this line is doing what you expect.

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]
  } 
else if (prop !== 'tracks' && value !== '') {
    records[id][prop] = value

  }
 else if (prop === 'tracks') {

    if (value !== '') {

      records[id].tracks = []
    }
  } 
if (prop === 'tracks' && value !== '') {

    records[id].tracks.push(value)
  }

  return records
}
console.log(updateRecords(recordCollection, 5439, "track", "Take a Chance on Me"))

still didnt pass

Ok, have you investigated why? Do you have more questions?

its passed thank you

1 Like

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