From d3ce09e85899110d225fcacf98cf6942de877898 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 10:21:47 -0500 Subject: [PATCH 01/13] updated html src tags --- challenges/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenges/index.html b/challenges/index.html index 5772804b7f..0dc5ec27dd 100644 --- a/challenges/index.html +++ b/challenges/index.html @@ -7,8 +7,8 @@ Sprint Challenge - - + + From a207b1bdb7bea3c963134ecd2a3bafe1f65363e7 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 10:35:33 -0500 Subject: [PATCH 02/13] task 1-3 done --- challenges/arrays-callbacks.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index 472ab3e96d..7f62f48b57 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -21,6 +21,11 @@ The zoos want to display both the scientific name and the animal name in front o */ const displayNames = []; +zooAnimals.forEach(function(currentValue){ + displayNames.push( + `Name: ${currentValue.animal_name}, Scientific: ${currentValue.scientific_name}.` + ); +}); console.log(displayNames); /* Request 2: .map() @@ -30,6 +35,10 @@ The zoos need a list of all their animal's names (animal_name only) converted to */ const lowCaseAnimalNames = []; +zooAnimals.map(function(currentValue){ + lowCaseAnimalNames.push( + currentValue.animal_name.toLowerCase()); +}); console.log(lowCaseAnimalNames); /* Request 3: .filter() @@ -38,6 +47,10 @@ The zoos are concerned about animals with a lower population count. Using filter */ const lowPopulationAnimals = []; +zooAnimals.filter(function(currentValue){ + lowPopulationAnimals.push( + currentValue.population < 5); +}); console.log(lowPopulationAnimals); /* Request 4: .reduce() From aaca07e9f0bc9d80ec19e6c952532a0c8920fdb8 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 10:40:21 -0500 Subject: [PATCH 03/13] task 4 arrays working --- challenges/arrays-callbacks.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index 7f62f48b57..5da9521cce 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -46,10 +46,8 @@ console.log(lowCaseAnimalNames); The zoos are concerned about animals with a lower population count. Using filter, create a new array of objects called lowPopulationAnimals which contains only the animals with a population less than 5. */ -const lowPopulationAnimals = []; -zooAnimals.filter(function(currentValue){ - lowPopulationAnimals.push( - currentValue.population < 5); +const lowPopulationAnimals = zooAnimals.filter(function(currentValue){ + return currentValue.population < 5; }); console.log(lowPopulationAnimals); @@ -58,7 +56,9 @@ console.log(lowPopulationAnimals); The zoos need to know their total animal population across the United States. Find the total population from all the zoos using the .reduce() method. Remember the reduce method takes two arguments: a callback (which itself takes two args), and an initial value for the count. */ -const populationTotal = 0; +const populationTotal = zooAnimals.reduce(function(callBackPopReduce, data){ + return callBackPopReduce + data.population; +}, 0); console.log(populationTotal); From 29f54f42e75481a59c48d5302724b88daf2c104b Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 10:43:09 -0500 Subject: [PATCH 04/13] first callback working, I think??? --- challenges/arrays-callbacks.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index 5da9521cce..f33cb809fc 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -71,6 +71,9 @@ console.log(populationTotal); * The consume function should return the invocation of cb, passing a and b into cb as arguments */ +function consume (a, b, cb){ + return cb(a, b); +} /* Step 2: Create several functions to callback with consume(); * Create a function named add that returns the sum of two numbers From 0d960fb0c60a2203ef6e1e33139bc48726d875a9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 10:46:21 -0500 Subject: [PATCH 05/13] second callback works! --- challenges/arrays-callbacks.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index f33cb809fc..70e0690ca5 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -81,6 +81,17 @@ function consume (a, b, cb){ * Create a function named greeting that accepts a first and last name and returns "Hello first-name last-name, nice to meet you!" */ +function add(a, b){ + return a + b; +} + +function multiply(a, b){ + return a * b; +} + +function greeting(firstName, lastName){ + return `Hello ${firstName} ${lastName}, nice to meet you!`; +} /* Step 3: Check your work by un-commenting the following calls to consume(): */ // console.log(consume(2, 2, add)); // 4 From 57b2df88cc79f55455296f2f76a311a46762f7e1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 10:59:51 -0500 Subject: [PATCH 06/13] did the clossures.js tasks --- challenges/arrays-callbacks.js | 9 +++------ challenges/closure.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index 70e0690ca5..e7454c4b45 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -94,12 +94,9 @@ function greeting(firstName, lastName){ } /* Step 3: Check your work by un-commenting the following calls to consume(): */ -// console.log(consume(2, 2, add)); // 4 -// console.log(consume(10, 16, multiply)); // 160 -// console.log(consume("Mary", "Poppins", greeting)); // Hello Mary Poppins, nice to meet you! - - - +console.log(consume(2, 2, add)); // 4 +console.log(consume(10, 16, multiply)); // 160 +console.log(consume("Mary", "Poppins", greeting)); // Hello Mary Poppins, nice to meet you! /* diff --git a/challenges/closure.js b/challenges/closure.js index 101d68e553..b20182a779 100644 --- a/challenges/closure.js +++ b/challenges/closure.js @@ -18,7 +18,18 @@ myFunction(); // Explanation: +`A: nestedFunction can access the variable internal because they are both within the block level scope of myFunction.` /* 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(n){ + let counter = 0; + for (let i=1; i<= n; i++){ + counter += i; + } + return counter; +} + +console.log(summation(4)); \ No newline at end of file From 24a7af80febc9c899b35b3e8f40ecc0e547020ef Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 11:01:40 -0500 Subject: [PATCH 07/13] making sure pull request receives continued pushes --- challenges/prototypes.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenges/prototypes.js b/challenges/prototypes.js index 4cafc33e95..dddeb3b17c 100644 --- a/challenges/prototypes.js +++ b/challenges/prototypes.js @@ -27,7 +27,7 @@ */ // Test your volume and surfaceArea methods by uncommenting the logs below: -// console.log(cuboid.volume()); // 100 -// console.log(cuboid.surfaceArea()); // 130 +console.log(cuboid.volume()); // 100 +console.log(cuboid.surfaceArea()); // 130 From 63047174e8cefb280cabb4e05abd379aa9672f08 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 11:17:14 -0500 Subject: [PATCH 08/13] prototypes.js worksgit add .! --- challenges/prototypes.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/challenges/prototypes.js b/challenges/prototypes.js index dddeb3b17c..e5bbb0534a 100644 --- a/challenges/prototypes.js +++ b/challenges/prototypes.js @@ -6,6 +6,11 @@ Create a constructor function named CuboidMaker that accepts properties for length, width, and height */ +function CuboidMaker(attributes){ + this.length = attributes.length; + this.width = attributes.width; + this.height = attributes.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 @@ -13,6 +18,9 @@ Formula for cuboid volume: length * width * height */ +CuboidMaker.prototype.volume = function(){ + return this.length * this.width * this.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. @@ -20,14 +28,27 @@ Formula for cuboid surface area of a cube: 2 * (length * width + length * height + width * height) */ +CuboidMaker.prototype.surfaceArea = function(){ + return ( + 2 * + (this.length * this.width + + this.length * this.height + + this.width * this.height) + ); +}; + /* == Step 4: Create a new object that uses CuboidMaker == Create a cuboid object that uses the new keyword to use our CuboidMaker constructor Add properties and values of length: 4, width: 5, and height: 5 to cuboid. */ +let cuboid = new CuboidMaker({ + length: 4, + width: 5, + height: 5, +}); + // Test your volume and surfaceArea methods by uncommenting the logs below: console.log(cuboid.volume()); // 100 -console.log(cuboid.surfaceArea()); // 130 - - +console.log(cuboid.surfaceArea()); // 130 \ No newline at end of file From b8458e85fb30009a9f6afea2871856977ea9f158 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 11:21:58 -0500 Subject: [PATCH 09/13] classes.js working --- challenges/classes.js | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/challenges/classes.js b/challenges/classes.js index 992e39dc0b..4530250ab5 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -1,7 +1,32 @@ // 1. Copy and paste your prototype in here and refactor into class syntax. +class CuboidMaker2 { + constructor(attributes){ + this.length = attributes.length; + this.width = attributes.width; + this.height = attributes.height; + } + volume (){ + return this.length * this.width * this.height; + } + surfaceArea(){ + return ( + 2 * + (this.length * this.width + + this.length * this.height + + this.width * this.height) + ); + } +} + + let cuboid2 = new CuboidMaker2({ + length: 4, + width: 5, + height: 5, + }); + // Test your volume and surfaceArea methods by uncommenting the logs below: -// console.log(cuboid.volume()); // 100 -// console.log(cuboid.surfaceArea()); // 130 +console.log(cuboid2.volume()); // 100 +console.log(cuboid2.surfaceArea()); // 130 // Stretch Task: Extend the base class CuboidMaker with a sub class called CubeMaker. Find out the formulas for volume and surface area for cubes and create those methods using the dimension properties from CuboidMaker. Test your work by logging out your volume and surface area. \ No newline at end of file From e1b80a0aa353ce58c5296c5a918236addedca420 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 11:32:15 -0500 Subject: [PATCH 10/13] stretch goals on arrow functions --- challenges/arrays-callbacks.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index e7454c4b45..fa8096fbe3 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -103,4 +103,28 @@ console.log(consume("Mary", "Poppins", greeting)); // Hello Mary Poppins, nice t Stretch: If you haven't already, convert your array method callbacks into arrow functions. */ +const displayNames2 = []; +zooAnimals.forEach(currentValue => { + displayNames2.push( + `Name: ${currentValue.animal_name}, Scientific: ${currentValue.scientific_name}.` + ); +}); + +const lowCaseAnimalNames2 = []; +zooAnimals.map(currentValue => { + lowCaseAnimalNames2.push( + currentValue.animal_name.toLowerCase()); +}); + +const lowPopulationAnimals2 = zooAnimals.filter(currentValue => { + return currentValue.population < 5; +}); + +const populationTotal2 = zooAnimals.reduce((callBackPopReduce, data) => { + return callBackPopReduce + data.population; +}, 0); +console.log(displayNames2); +console.log(lowCaseAnimalNames2); +console.log(lowPopulationAnimals2); +console.log(populationTotal2); \ No newline at end of file From def1cf8996ca82973ca67d2bf417269ca98f33aa Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 11:41:06 -0500 Subject: [PATCH 11/13] stretch task cubemaker --- challenges/classes.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/challenges/classes.js b/challenges/classes.js index 4530250ab5..df28a8a5f3 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -29,4 +29,25 @@ class CuboidMaker2 { console.log(cuboid2.volume()); // 100 console.log(cuboid2.surfaceArea()); // 130 -// Stretch Task: Extend the base class CuboidMaker with a sub class called CubeMaker. Find out the formulas for volume and surface area for cubes and create those methods using the dimension properties from CuboidMaker. Test your work by logging out your volume and surface area. \ No newline at end of file +// Stretch Task: Extend the base class CuboidMaker with a sub class called CubeMaker. Find out the formulas for volume and surface area for cubes and create those methods using the dimension properties from CuboidMaker. Test your work by logging out your volume and surface area. + +class CubeMaker extends CuboidMaker { + constructor(attributes){ + super(attributes); + } + CubeVolume(){ + return this.length * this. width * this.height; + } + CubeSurfaceArea(){ + return 2 * (this.length * this.length + this.width * this.width + this.height * this.height); + } +} + +let cube = new CubeMaker ({ + length: 5, + width: 5, + height: 5, +}); + +console.log(cube.CubeVolume()); // 125 +console.log(cube.CubeSurfaceArea()); // 150 \ No newline at end of file From ac498224bda58ff7c18760e9170585d279d9cbba Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 12:12:44 -0500 Subject: [PATCH 12/13] readme questions answered --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index cc6d6902fb..5bfbbd6c08 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,28 @@ 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) +A: .forEach is sort of like a for loop in that it iterates through every item in an array and does something to the original array whereas .map leave the original array alone while creating a new array with something done to the data from the original array before returning it. + 2. Explain the difference between a callback and a higher order function. +A: A callback is a function which is passed into a higher order function as a parameter whereas a higher order function is a function which takes a callback as a parameter. + 3. What is closure? +A: A synonym for hell on earth...JK, JK...but for reals!!! Closure is the ability to put two or more functions together and gives the ability to access functions that are in a child level scope from a parent level scope even after the parent level function has been terminated. Yeah, try to say that ten times fast without smiling :) + 4. Describe the four rules of the 'this' keyword. +A: So depending on the use of the "this" keyword, it will be used in different ways, called binding, which refers to what "this" binds to. + a) In global binding, the value of this is the window or console unit. It's like everything. + b) In implicit binding, the object to the left of the dot gets the "this. + c) In new binding, when a constructor function is used, this refers to the specific instance of the object created by the constructor function. + d) In explicit binding, whenever call, apply, or bind methods are used, this is explicity defined within the method. + 5. Why do we need super() in an extended class? +A: Super is used to get data to be used in a child from a parent object. + ### Task 1 - Project Set up Follow these steps to set up and work on your project: From 44eba18ac6df7807d7438ef55750916b8934df10 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 22 May 2020 16:17:44 -0500 Subject: [PATCH 13/13] made some stylistic changes based on Christine's feedback --- challenges/arrays-callbacks.js | 37 ++++++++++++++++++++++++---------- challenges/classes.js | 12 +++++++++-- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index fa8096fbe3..78a4cfe5d8 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -21,11 +21,14 @@ The zoos want to display both the scientific name and the animal name in front o */ const displayNames = []; + zooAnimals.forEach(function(currentValue){ displayNames.push( - `Name: ${currentValue.animal_name}, Scientific: ${currentValue.scientific_name}.` + `Name: ${currentValue.animal_name}, + Scientific: ${currentValue.scientific_name}.` ); }); + console.log(displayNames); /* Request 2: .map() @@ -35,10 +38,12 @@ The zoos need a list of all their animal's names (animal_name only) converted to */ const lowCaseAnimalNames = []; + zooAnimals.map(function(currentValue){ lowCaseAnimalNames.push( currentValue.animal_name.toLowerCase()); }); + console.log(lowCaseAnimalNames); /* Request 3: .filter() @@ -46,9 +51,12 @@ console.log(lowCaseAnimalNames); The zoos are concerned about animals with a lower population count. Using filter, create a new array of objects called lowPopulationAnimals which contains only the animals with a population less than 5. */ -const lowPopulationAnimals = zooAnimals.filter(function(currentValue){ +const lowPopulationAnimals = zooAnimals.filter( + function(currentValue){ return currentValue.population < 5; -}); + } +); + console.log(lowPopulationAnimals); /* Request 4: .reduce() @@ -56,9 +64,11 @@ console.log(lowPopulationAnimals); The zoos need to know their total animal population across the United States. Find the total population from all the zoos using the .reduce() method. Remember the reduce method takes two arguments: a callback (which itself takes two args), and an initial value for the count. */ -const populationTotal = zooAnimals.reduce(function(callBackPopReduce, data){ - return callBackPopReduce + data.population; -}, 0); +const populationTotal = zooAnimals.reduce( + function(callBackPopReduce, data){ + return callBackPopReduce + data.population; + }, 0); + console.log(populationTotal); @@ -104,24 +114,29 @@ Stretch: If you haven't already, convert your array method callbacks into arrow */ const displayNames2 = []; + zooAnimals.forEach(currentValue => { displayNames2.push( - `Name: ${currentValue.animal_name}, Scientific: ${currentValue.scientific_name}.` + `Name: ${currentValue.animal_name}, + Scientific: ${currentValue.scientific_name}.` ); }); const lowCaseAnimalNames2 = []; + zooAnimals.map(currentValue => { lowCaseAnimalNames2.push( currentValue.animal_name.toLowerCase()); }); -const lowPopulationAnimals2 = zooAnimals.filter(currentValue => { - return currentValue.population < 5; +const lowPopulationAnimals2 = zooAnimals.filter( + currentValue => { + return currentValue.population < 5; }); -const populationTotal2 = zooAnimals.reduce((callBackPopReduce, data) => { - return callBackPopReduce + data.population; +const populationTotal2 = zooAnimals.reduce( + (callBackPopReduce, data) => { + return callBackPopReduce + data.population; }, 0); console.log(displayNames2); diff --git a/challenges/classes.js b/challenges/classes.js index df28a8a5f3..14172bd034 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -36,10 +36,18 @@ class CubeMaker extends CuboidMaker { super(attributes); } CubeVolume(){ - return this.length * this. width * this.height; + return ( + this.length * + this. width * + this.height + ); } CubeSurfaceArea(){ - return 2 * (this.length * this.length + this.width * this.width + this.height * this.height); + return 2 * ( + this.length * this.length + + this.width * this.width + + this.height * this.height + ); } }