Skip to content

Instantly share code, notes, and snippets.

@revisualize
Last active February 4, 2017 09:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save revisualize/123deb77d85079f079020ac3cd6ea5ba to your computer and use it in GitHub Desktop.
Save revisualize/123deb77d85079f079020ac3cd6ea5ba to your computer and use it in GitHub Desktop.
The FreeCodeCamp.com Record Collection check point with the instructions laid out in comments.
// Record Collection: (I have added the instructions to the comments.)
// First we need to understand that collection is an object with children objects.
// collections is an object with 4 properties: 2548, 2468, 1245 & 5439
// Each of those object properties have a child object.
// Those child objects can have up to three properties: album, artist & tracks
// Of those album & artist are strings and tracks is an array.
// Write a function which takes an album's id (like 2548),
// a property key (or name) ... prop (like "artist" or "tracks"),
// and a value (like "Addicted to Love")
function updateRecords(id, prop, value) {
// If prop isn't "tracks" and value isn't an empty string (""),
// update or set the value for that record album's property.
// Your code here
// If prop is "tracks" and value isn't an empty string (""),
// push the value onto the end of the album's existing tracks array.
// If prop is "tracks" but the album doesn't have a "tracks" property,
// create an empty array before adding the new value to the album's
// corresponding property.
// Your code here
// If value is an empty string (""),
// delete that property from the album.
// Your code here
return collection;
}
/* Hints:
Mozilla Developer Network - Working with objects
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
Use bracket notation when accessing object properties with variables.
https://www.freecodecamp.com/challenges/accessing-objects-properties-with-variables
Push is an array method you can read about on Mozilla Developer Network.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push
Extra Hint:
Testing Objects for Properties
https://www.freecodecamp.com/challenges/testing-objects-for-properties
*/
@revisualize
Copy link
Author

revisualize commented Oct 18, 2016

Parameters are variables that represent the values that get passed into your function from the function call.
https://cs.wellesley.edu/~cs110/lectures/L16/images/function-anatomy.png
Notice how the variables level and score in the function definition addScore are called parameters.
However, when we invoke the function like in:
addScore(3, 10) or addScore(6, 20)
the values are called arguments. Here is an important lesson:
You define a function with parameters, you call a function with arguments.

Another example of this:

function hello(fName, uName) {
     return "Hello " + fName + " " + uName + ", How is your day?";
}
hello("Joseph", "@revisualize"); // "Hello Joseph @revisualize, How is your day?"
hello("Bella", "@bellaknoti"); // "Hello Bella @bellaknoti, How is your day?"
hello("Andy", "@dirn"); // "Hello Andy @dirn, How is your day?"

You can use the fName and uName parameters just like a variable inside of your function.

Other important things to remember:
* A function can have zero parameters. You still have to use the parentheses to define it.
* A function might have no return statements. In this case we say that the function returns undefined.

With the updateRecords function you get three parameters to use when you're building how your function works: id, prop & value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment