Basic JavaScript - Record Collection

Tell us what’s happening:
here terminal says tracks is not defined.

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

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

This is the first time you use the variable tracks. Where did you define it?

bro I cannot understand can you plz explain me the whole code

Now it is my turn to not understand.
Do you want me to explain your code to you?
Shouldn’t it be the opposite? (you explain what you wrote to me?)

yes bro I didnot defined it but how can I solve it man

can You plz give me solution and also explain me

Nobody here is going to give you a solution. We will give hints and try and guide you to answers. The point is you should be learning these things. Us giving you the answer is not helping you solve these problems and making you better at coding.

If you just type tracks into JavaScript its going to assume you are talking about some variable. And JavaScript is not seeing it, so its yelling at you that its missing. These are things you should look for when you see that error. Did you make a variable named tracks anywhere? Is it there but out of scope? Did you make a typo? You should know how to define a variable, let tracks. That will fix the error message, but that’s not really the problem here.

The thing is should tracks be a variable? If you look at the arguments being sent to the function it should give you a hint as to what type of data tracks should be if your are comparing it to prop. What type of data is prop holding? What type of data are property names in an object?

You have other problems with your code, but solve that first and keep asking questions and we will help.

2 Likes
// 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
if(prop != tracks && value!=""){
return record[id][prop]=value;
}else if(prop == tracks && id !=tracks){
  value =[];
}
function updateRecords(records, id, prop, value) {
  return records;
}

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

I dont get it Can you plz again make me understand

If you understand how functions are called and arguments work you should be able to tell me what data type is stored in prop.

If you don’t understand these things it can be hard to tell what is going on in a function, and it will be very confusing and hard to pass most of these tests on your own.

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