diff --git a/README.md b/README.md index cc6d6902fb..9dfc8b5d56 100644 --- a/README.md +++ b/README.md @@ -26,27 +26,49 @@ Edit this document to include your answers after each question. Make sure to lea 1. Briefly compare and contrast `.forEach` & `.map` (2-3 sentences max) +The map method receives a function as a parameter. Then it applies it on each element and returns an entirely new array populated with the results of calling the provided function. Like map , the forEach() method receives a function as an argument and executes it once for each array element. However, instead of returning a new array like map, it returns undefined. + 2. Explain the difference between a callback and a higher order function. +A higher-order function is a function that takes another function(s) as an argument(s) and/or returns a function to its callers. + +A callback function is a function that is passed to another function with the expectation that the other function will call it. + 3. What is closure? +A closure is a feature in JavaScript where an inner function has access to the outer (enclosing) function’s variables — a scope chain. + + + 4. Describe the four rules of the 'this' keyword. +Whenever a function is contained in the global scope, the value of this inside of that function will be the window object. + +Whenever a function is called by a preceding dot, the object before that dot is this. + +Whenever a constructor function is used, this refers to the specific instance of the object that is created and returned by the constructor function. + +Whenever JavaScript’s call or apply method is used, this is explicitly defined. + + + 5. Why do we need super() in an extended class? +The super keyword in JavaScript is used in order to call the methods of the parent class. By itself, super() is used within a constructor function to call the parent constructor function. + ### Task 1 - Project Set up Follow these steps to set up and work on your project: Make sure you clone the branch that the TK links to: the vnext branch, NOT master! -- [ ] Create a forked copy of this project. -- [ ] Add TL as collaborator on Github. -- [ ] Clone your OWN version of Repo (Not Lambda's by mistake!). -- [ ] Create a new Branch on the clone: git checkout -b ``. -- [ ] Create a pull request before you start working on the project requirements. You will continuously push your updates throughout the project. -- [ ] You are now ready to build this project with your preferred IDE -- [ ] Implement the project on your Branch, committing changes regularly. -- [ ] Push commits: git push origin ``. +- [ done] Create a forked copy of this project. +- [ done ] Add TL as collaborator on Github. +- [ done ] Clone your OWN version of Repo (Not Lambda's by mistake!). +- [ done ] Create a new Branch on the clone: git checkout -b ``. +- [ done ] Create a pull request before you start working on the project requirements. You will continuously push your updates throughout the project. +- [ done ] You are now ready to build this project with your preferred IDE +- [ done ] Implement the project on your Branch, committing changes regularly. +- [ done ] Push commits: git push origin ``. diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index 472ab3e96d..a4a0bac7c5 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -20,9 +20,15 @@ const zooAnimals = [ The zoos want to display both the scientific name and the animal name in front of the habitats. Populate the displayNames array with only the animal_name and scientific_name of each animal. displayNames will be an array of strings, and each string should follow this pattern: "Name: Jackal, asiatic, Scientific: Canis aureus." */ -const displayNames = []; + +zooAnimals.forEach(function(displayNames){ + + +const displayNames = [animal_name, scientific_name]; console.log(displayNames); +}); + /* Request 2: .map() The zoos need a list of all their animal's names (animal_name only) converted to lower case. Using map, create a new array of strings named lowCaseAnimalNames, each string following this pattern: "jackal, asiatic". Log the resut. diff --git a/challenges/classes.js b/challenges/classes.js index 992e39dc0b..3196a997cb 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -1,5 +1,29 @@ // 1. Copy and paste your prototype in here and refactor into class syntax. +function CupoidMaker(attributes) { + this.length = attributes.length; + this.width = attributes.width; + this.height = attributes.height; + } + + CupoidMaker.prototype.volume = function () { + return (length*width*height); + }; + + + class CupoidMaker { + constructor(attributes) { + this.length = attributes.length; + this.width = attributes.width; + this.height = attributes.height; + } + volume() { + return (length*witdth*height) + } + } + + + // Test your volume and surfaceArea methods by uncommenting the logs below: // console.log(cuboid.volume()); // 100 // console.log(cuboid.surfaceArea()); // 130 diff --git a/challenges/closure.js b/challenges/closure.js index 101d68e553..17af905712 100644 --- a/challenges/closure.js +++ b/challenges/closure.js @@ -16,9 +16,18 @@ function myFunction() { } myFunction(); -// Explanation: +// Explanation: Internal is located within the nested function, so it is within the scope, therefore can be accessed. /* Task 2: Counter */ /* Create a function called `sumation` that accepts a parameter and uses a counter to return the summation of that number. For example, `summation(4)` should return 10 because 1+2+3+4 is 10. */ + +function summation(a) { + + return function(b) { + return a + b; // takes "a" from the outer lexical environment + }; + +} + diff --git a/challenges/prototypes.js b/challenges/prototypes.js index 4cafc33e95..ccf1eb35ae 100644 --- a/challenges/prototypes.js +++ b/challenges/prototypes.js @@ -6,13 +6,25 @@ Create a constructor function named CuboidMaker that accepts properties for length, width, and height */ +function CupoidMaker(length, width, height) { + this.length = length; + this.width = width; + this.height = height; + +} /* == Step 2: Volume Method == Create a method using CuboidMaker's prototype that returns the volume of a given cuboid's length, width, and height Formula for cuboid volume: length * width * height */ +function CupoidMaker(length, width, height) { + this.length = length; + this.width = width; + this.height = height; +} +CupoidMaker.prototype.volume = (length * width * height); /* == Step 3: Surface Area Method == Create another method using CuboidMaker's prototype that returns the surface area of a given cuboid's length, width, and height.