Basic JavaScript - Record Collection

Tell us what’s happening:
I don’t understand what I am doing wrong here :frowning: , only one test passes so far.

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[prop];

  }
  else if(prop!='tracks' && value!=''){
    records[prop]=value;
  }
  else if(prop=='tracks' && value!=''){
    if(records.hasOwnProperty(prop)){
      records[prop]+=[value];

    }
    else{
      records[prop]=[value];
    }

  }
  return records;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

I suspect this line doesn’t do what you think?

add to the existing array ?
should i use push then ?
update:it’s still not working in freecodecamp editor(the very first test)
However in another editor it gives:


The second test also works :
image

Yes

it’s still not working in freecodecamp editor however it works the first two tests in another online editor.

What is ‘it’? What’s your updated code?


I’ve noticed that you don’t seem to be using id anywhere? It’s given as an argument, so you’re intended to use it.

When I run this code above I get an error message “collection not defined” Can you please shed some light on how to define collection.

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

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