Basic Javascript (93/111) | Record Collection | freeCodeCamp

preview_player
Показать описание
Basic Javascript (93/111) | Record Collection | freeCodeCamp

You are given a JSON object representing a part of your musical album collection. Each album has a unique id number as its key and several other properties. Not all albums have complete information.

You start with an updateRecords function that takes an object like collection, an id, a prop (like artist or tracks), and a value. Complete the function using the rules below to modify the object passed to the function.

Your function must always return the entire object.
If prop isn't tracks and value isn't an empty string, update or set that album's prop to value.
If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it.
If prop is tracks and value isn't an empty string, add value to the end of the album's existing tracks array.
If value is an empty string, delete the given prop property from the album.
Note: A copy of the collection object is used for the tests.

Hints:
- use "if...else if" for each step
- use records[id][prop] to access the value of a key in this object
- use hasOwnProperty to check if the array exists before push

#Javascript #RecordCollection #freeCodeCamp
Рекомендации по теме
Комментарии
Автор

it is the only right and updated video .helped me thanks.

suryakiranreddy
Автор

the javascript portion of the freecodecamp is not that suitable for beginners, and so it makes a lot of people get stuck almost in every page. hopefully freecodecamp will be aware of this and mitigate the issue. the html and css is noob friendly, too bad the javascript lessons are not geared that way. by the way, thank you for your videos. it really helped a lot.

gisellejanen
Автор

Thanks 🙏. I appreciate seeing the way you code which is less cluttered but I’m of course still learning. Thanks for the video I wouldn’t have passed this lesson without your help!

thepewbroswreeo
Автор

can you do a voice over explaining exactly what you are doing thanks

somewhereinspace
Автор

Thank you so much. I have been stuck on this for a bit!

zanyomemes
Автор

video quality is pretty bad. Almost thought I wasn't wearing my glasses for a second, then realized I don't wear glasses.

daleputnam
Автор

I have just solved this one, but there's a mistake in the instructions. Here is what it says: "If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it". The problem is that you might think it is not necessary to add the array to the object.

peristiloperis
Автор

I was quite happy going through the free code camp lessons until I got to this part, needed to look at the hints and still don't full understand the full solution.

else if (prop == 'tracks' && === false){
records[id][prop] = [value];

Why does the [value] on this line require it to be in [ ]

jordanking
Автор

in updated challenge change object with value it will pass

sikandarfarooqsaani
Автор

Hi, thanxx for help, just a question, how much time it takes you to be in this level in JS ?

bengen
Автор

That sound while trying to understand a logic challenge is totally unnecessary and annoying. Just a feedback.

andreainvernizzi