Basic JavaScript - Record Collection - bXOu4mclvZXvDyQqUUiF3

Hello - thanks for that camp, i’m not new in the IT but noob in JS,
so I’ve try that lesson - one day is gone … and now I’ve a question.

I start with help from video, try my self ‘solution’ and same form forum - no luck.
ok back too roots and try only one by one condition and check exactly that it do …

Can it be that delete recordCollection[id][prop]; deletes more in that env as it should.
Check it in codepen.io who it do rigth.

great, you can see my ‘work’, so here also console output - as I see, propertie artist is also gone?

Thank you for Help.

// — console --_
Start Func: [object Object] 2548 tracks
no value so DO delete: 2548 tracks - next line(s) array befor and after delete
so artist is also ‘gone’??
{ albumTitle: ‘Slippery When Wet’,
artist: ‘Bon Jovi’,
tracks: [ ‘Let It Rock’, ‘You Give Love a Bad Name’ ] }
{ albumTitle: ‘Slippery When Wet’, artist: ‘Bon Jovi’ }

// — EOF —

  **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) {
console.log("Start Func: "+records+" " +id+" "+ prop +" "+ value);
 if(!value){
  console.log("no value so DO delete: " + id + " " + prop + " - next line(s) array befor and after delete 
 so artist is also 'gone'??");
  console.log(recordCollection[id]);
  delete recordCollection[id][prop]; 
  console.log(recordCollection[id]); 
 }
}

//updateRecords(recordCollection, 5439, 'artist', 'ABBA');
//updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me");
//console.log('id 5439 tracks: ' + recordCollection[5439].tracks)
///*updateRecords(recordCollection, 2548, "artist", "");
//updateRecords(recordCollection, 1245, "tracks", "Addicted to Love");
//updateRecords(recordCollection, 2468, "tracks", "Free");

updateRecords(recordCollection, 2548, "tracks", "");
//updateRecords(recordCollection, 1245, "albumTitle", "Riptide")
//*/
//console.log(recordCollection);




  **Your browser information:**

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:101.0) Gecko/20100101 Firefox/101.0

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

You should only use records. You should ignore the recordCollection global variable.

Why gone? It’s in your last line of log

Thank you - I’ll will looking too.

console.log ? I think it is that:

{ albumTitle: ‘Slippery When Wet’,
artist: ‘Bon Jovi’,
tracks: [ ‘Let It Rock’, ‘You Give Love a Bad Name’ ] }
{ albumTitle: ‘Slippery When Wet’, artist: ‘Bon Jovi’ }

so last line has propertie albumTitle but only - where is artist , then I try to
delete recordCollection[id][prop];
and prop is tracks …

Ahh re-read mail …
you are right - a one liner, so need a try again. Thanks !

you have both albumTitle and artist there…

Hello ilenia,
I’ve rewritten that lesson - video has helped… but also no luck. I’ve try that also in codepen.io and I think it works. Code at end of mail.
#x are my conditions intern Numbers - console.log trace simply id, param and value …

running test say not success at:

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.
=>>> but in console log:
start function - para: 5439 tracks Take a Chance on Me
#3 & 4 - prop ‘tracks’ 5439 tracks Take a Chance on Me

  • after update #3&4 array[id][prop] is: Take a Chance on Me

After updateRecords(recordCollection, 2548, "artist", ""), artist should not be set
=>>>but in console.log:
start function - para: 2548 artist
#5 no value 2548 artist

  • after update #5 array[id][prop] is: undefined

After updateRecords(recordCollection, 2548, "tracks", ""), tracks should not be set
=>>>but in console.log
start function - para: 2548 tracks
#5 no value 2548 tracks

  • after update #5 array[id][prop] is: undefined

so I think all conditions are fulfilled, do you have any hint for me?
it is my last lessen, I’m at 99% so I’ll be happy to solve that last thing.

Thanks for your patience
Regards.

// # # # here my code - and output in freecodecamp.com # # #

 // 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) {
  
  console.log("start function - para:  "+id+" "+prop+" "+value)
  //zu 5 - empty value
  if (!value) {
    console.log("#5 no value " + id + " " + prop + " " + value);
    delete recordCollection[id][prop];
    console.log("  - after update #5 array[id][prop] is: " + recordCollection[id][prop]);
    //zu 3 u. 4 - if prop == tracks && value in 5.)  ->   set/Update value
  } else if (prop == 'tracks') {
    console.log("#3 & 4 - prop 'tracks' " + id + " " + prop + " " + value);
    recordCollection[id][prop] = recordCollection[id][prop] || [];
    recordCollection[id][prop].push(value);
    console.log("  - after update #3&4 array[id][prop] is: " + recordCollection[id][prop]);
    //zu 2. - prop not tracks 
  } else if (prop != 'tracks') {
    console.log("#2 not prop 'tracks' " + id + " " + prop + " " + value);
    recordCollection[id][prop] = value;
    console.log("  - after update #2 array[id][prop] is: " + recordCollection[id][prop]);
  }
  //zu 1
  return recordCollection;

}

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

///////// log window ///////////
hmmm - no simple copy & paste possible, but I’ve written the most above

You still cannot reference the global variable. Ignoring the first function argument will cause your function to fail to meet the requirements.

Hi JeremyLT, Yes you are right ! That do the trick …
I do not know (this time) what ‘piece’ of array exactly is in the function, also in records but I should realise that.
So now I’m ready for the next part.

Can/should I mark that as solved?

it’s marked as solved.

you can mark a topic as solved by marking one of the posts in it as solution

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