Basic Javascript (93/111) | Record Collection | freeCodeCamp
Full playlist 👉 • Basic JavaScript (1/111) | Comment Your Ja...
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
https://www.freecodecamp.org/learn/ja...
#Javascript #RecordCollection #freeCodeCamp
On this page of the site you can watch the video online Basic Javascript (93/111) | Record Collection | freeCodeCamp with a duration of hours minute second in good quality, which was uploaded by the user Stral Tech 27 November 2020, share the link with friends and acquaintances, this video has already been watched 6,000 times on youtube and it was liked by 61 viewers. Enjoy your viewing!