Build a Record Collection - Build a Record Collection

Tell us what’s happening:

Hi, need a little help here, just can’t figure out why not working. Thanks alot.

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 updateRecords[prop] }

else if(value != "tracks" && value != "")
{value === records[prop]}

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

else if(records[prop] = "tracks" && value != "")
{records[id].tracks.push(value);}

else{console.log("Errorrrrrrrr")}; 

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

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

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/143.0.0.0 Safari/537.36 Edg/143.0.0.0

Challenge Information:

Build a Record Collection - Build a Record Collection

Hi @timduncan0322

For test 2, console log the variables and conditions.

You’ll need to keep the first function call, comment out the rest.

Make sure they have the expected values.

Happy coding

i tried comment out the other “else if” and console log, but still not working, is something wrong with th line below?

if(value = “”){delete records[prop]}

else if(value != “tracks” && value != “”&& id != “”)

{value === records[prop]}

are you sure you want to change the value of value?

isn’t it just check if value is relly empty, then apply change to records[prop]? Sorry that I am not quite following.

no, = is not an operator that checks for equality
that is the assignment operator

ok thanks, I have fixed this, now i am facing how I can target the id in the function, as I find all changes goes to the last id, any hint? Thanks.

can you post your updated code?

Hi @timduncan0322

Console logrecords[prop]

Is that what you are expecting?

Happy coding

I tried with different approach, but still not working, can’t push the new item to the end of Tracks.

function updateRecords(records, id, prop, value){

if(value == “”){delete records[id][prop]}

else if(value != “tracks” && value != “”)

{records[id][prop] = value}

else if(updateRecords[prop] == “tracks” && value != “”)

{records[id][tracks.lenght - 1] = value}

else{console.log(“Errorrrrrrrrrrr”)};

return records;

}

also tried this still not working, I really dont understand, sorry about this.

function updateRecords(records, id, prop, value){

if(value == “”){delete records[id][prop]}

else if(value != ‘tracks’ && value != “”)

{records[id][prop] = value}

else if(updateRecords[prop] == ‘tracks’ && value != “”){records[id].prop.push(value)}

else{console.log(“Errorrrrrrrrrrr”)};

return records;

}

have you tried seeing what console.log(records[prop]) prints to the console?

it is not defined, but shouldn’t records, id, prop and value only exist within the function? Thanks.

you should add console.log(records[prop]) inside the function

if you do console.log(prop) you should see a value, but console.log(records[prop]) should give undefined, can you figure out why? look carefully at the object

i think linkage between records and id, prop and value are not there? is there a chapter about it so I can understand more? Thanks.

this is about accessing objects with variables

look carefully at how the records object is constructed, notice what keys it has

from previous chapter I can only find access to specific object, how can I access to a object subclass? Sorry for all these questions, I am not good with coding.

did you go back to this one? https://www.freecodecamp.org/learn/javascript-v9/lecture-introduction-to-javascript-objects-and-their-properties/how-do-you-work-with-accessing-properties-from-nested-objects-and-arrays-in-objects

yes, but I need to access the whole subclass in the array (albumTitle, artist, tracks), and I couldn’t see how I can delcare prop for this, the chapter only shows how to access single property, so i don’t how to do this.

you have an object, right? this object has properties like 2548, 2468, 1245 etc

how do you access the properties of this object? you need to do that first, then you can access the properties of the nested object