From 698c9c60dce6b26f21b7b7a100c3dcaadcf2f70c Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 20:32:44 -0500 Subject: [PATCH 01/19] working on first issues in objects-arrays.js --- challenges/objects-arrays.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index 86970b0c29..fa5a76a649 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -5,6 +5,32 @@ Use this pattern to create your objects: object name, diet, weight, length, period */ +let tRex = { + name: tyrannosaurus, + diet: carnivorous, + weight: 7000 kg, + length: 12 m, + period: Late Cretaceous, + roar: function roar() { + return `RAWERSRARARWERSARARARRRR!`; + } +} + +let steg = { + name: stegosaurus, + diet: herbivorous, + weight: 2000 kg, + length: 9 m, + period: Late Jurassic, +} + +let velo = { + name: velociraptor, + diet: carnivorous, + weight: 15 kg, + length: 1.8 m, + period: Late Cretaceous, +} // tyrannosaurus, carnivorous, 7000kg, 12m, Late Cretaceous @@ -15,20 +41,20 @@ // Using your dinosaur objects, log answers to these questions: // How much did tyrannosaurus weigh? -console.log(); +console.log(tRex.weight); // What was the diet of a velociraptor? -console.log(); +console.log(velo.diet); // How long was a stegosaurus? -console.log(); +console.log(steg.length); // What time period did tyrannosaurus live in? -console.log(); +console.log(tRex.period); // Create a new roar method for the tyrannosaurus. When called, return "RAWERSRARARWERSARARARRRR!" Log the result. -console.log(); +console.log(tRex.roar()); // ==== Arrays ==== From 147a8e75de3b9dbe84c2687e1be6189a15808777 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 20:47:47 -0500 Subject: [PATCH 02/19] passed Dinosaurs tasks --- challenges/objects-arrays.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index fa5a76a649..cd80cdde4c 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -6,30 +6,30 @@ object name, diet, weight, length, period */ let tRex = { - name: tyrannosaurus, - diet: carnivorous, - weight: 7000 kg, - length: 12 m, - period: Late Cretaceous, + name: 'tyrannosaurus', + diet: 'carnivorous', + weight: '7000 kg', + length: '12 m', + period: 'Late Cretaceous', roar: function roar() { return `RAWERSRARARWERSARARARRRR!`; } } let steg = { - name: stegosaurus, - diet: herbivorous, - weight: 2000 kg, - length: 9 m, - period: Late Jurassic, + name: 'stegosaurus', + diet: 'herbivorous', + weight: '2000 kg', + length: '9 m', + period: 'Late Jurassic', } let velo = { - name: velociraptor, - diet: carnivorous, - weight: 15 kg, - length: 1.8 m, - period: Late Cretaceous, + name: 'velociraptor', + diet: 'carnivorous', + weight: '15 kg', + length: '1.8 m', + period: 'Late Cretaceous', } // tyrannosaurus, carnivorous, 7000kg, 12m, Late Cretaceous From c79938049edf033adcf87a902057d4419a55790c Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 20:56:12 -0500 Subject: [PATCH 03/19] passed arrays request1 --- challenges/objects-arrays.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index cd80cdde4c..4a26b0102a 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -76,8 +76,10 @@ const graduates = [ /* Request 1: Create a new array called universities that contains all the universities in the graduates array. This will be an array of strings. + Once you have the new array created, log the result. */ const universities = []; +let gradUniversities = graduates.filter(graduates => universities.push(graduates.university)); console.log(universities); /* Request 2: Create a new array called contactInfo that contains both first name and email of each student. This will be an array of strings. From 5db2abe0c775ee5738463d5eaef25da922fe387a Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 21:07:51 -0500 Subject: [PATCH 04/19] passed arrays request2 --- challenges/objects-arrays.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index 4a26b0102a..c5a5176923 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -83,12 +83,12 @@ let gradUniversities = graduates.filter(graduates => universities.push(graduates console.log(universities); /* Request 2: Create a new array called contactInfo that contains both first name and email of each student. This will be an array of strings. - The resulting contact information strings should have a space between the first name and the email, like this: "Josh josh@example.com" Log the result of your new array. */ const contactInfo = []; +let conacts = graduates.forEach(graduates => contactInfo.push(graduates.first_name + " " + graduates.email)); console.log(contactInfo); /* Request 3: Find out how many universities have the string "Uni" included in their name. Create a new array called unisWithUni that contains them all. This will be an array of objects. Log the result. */ From 67be0549bb3cd0f7ce8b0236d5cd7cef45545661 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 22:02:23 -0500 Subject: [PATCH 05/19] passed arrays request3 --- challenges/objects-arrays.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index c5a5176923..a68555cca1 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -93,9 +93,9 @@ console.log(contactInfo); /* Request 3: Find out how many universities have the string "Uni" included in their name. Create a new array called unisWithUni that contains them all. This will be an array of objects. Log the result. */ const unisWithUni = []; -console.log(unisWithUni); - +graduates.forEach(graduates => { graduates.university.includes('Uni') ? unisWithUni.push(graduates.university) : false }); +console.log(unisWithUni); // ==== ADVANCED Array Methods ==== // Given this zoo data from around the United States, follow the instructions below. Use the specific array methods in the requests below to solve the problems. From f6f606f5e0cc6cb0c939ada7fd77cd8783b8c992 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 22:12:06 -0500 Subject: [PATCH 06/19] passed Adv Array Meth request1 --- challenges/objects-arrays.js | 1 + 1 file changed, 1 insertion(+) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index a68555cca1..c9657aae45 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -119,6 +119,7 @@ The zoos want to display both the scientific name and the animal name in front o */ const displayNames = []; +zooAnimals.forEach(zooAnimals => { displayNames.push(zooAnimals.animal_name + ", " + zooAnimals.scientific_name) }); console.log(displayNames); /* Request 2: .map() From 39fd4e6385b4ea0917a3f18cfbf539438813ea1e Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 22:19:08 -0500 Subject: [PATCH 07/19] passed Adv Array Meth request2 --- challenges/objects-arrays.js | 1 + 1 file changed, 1 insertion(+) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index c9657aae45..063fd9c590 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -129,6 +129,7 @@ The zoos need a list of all their animal's names (animal_name only) converted to */ const lowCaseAnimalNames = []; +zooAnimals.map(zooAnimals => { lowCaseAnimalNames.push(zooAnimals.animal_name.toLowerCase()) }); console.log(lowCaseAnimalNames); /* Request 3: .filter() From 852502b3960888443adf9e6b43a42ebee4025ffd Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 22:27:24 -0500 Subject: [PATCH 08/19] passed Adv Array Meth request 3 --- challenges/objects-arrays.js | 1 + 1 file changed, 1 insertion(+) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index 063fd9c590..59f0bf062c 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -138,6 +138,7 @@ The zoos are concerned about animals with a lower population count. Using filter */ const lowPopulationAnimals = []; +zooAnimals.filter(zooAnimals => { (zooAnimals.population < 5) ? lowPopulationAnimals.push(zooAnimals.animal_name) : false }); console.log(lowPopulationAnimals); /* Request 4: .reduce() From 271b2fd0915ea23f2ee54bc427e71a5017082139 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 22:39:23 -0500 Subject: [PATCH 09/19] moving on to the next js file --- challenges/objects-arrays.js | 1 + 1 file changed, 1 insertion(+) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index 59f0bf062c..46f8618aca 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -147,6 +147,7 @@ The zoos need to know their total animal population across the United States. Fi */ const populationTotal = 0; +zooAnimals.population.reduce(cb, populationTotal) console.log(populationTotal); From 44b8d2cb9140a7c12326a75cd2a2c100fdc7c70d Mon Sep 17 00:00:00 2001 From: JenVest2020 <61572583+JenVest2020@users.noreply.github.com> Date: Fri, 1 May 2020 22:45:57 -0500 Subject: [PATCH 10/19] Answered Study Questions --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index 408612117c..b93d0dad30 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,36 @@ Edit this document to include your answers after each question. Make sure to lea 1. Describe the biggest difference between `.forEach` & `.map`. +The .map method stores return values and returns a new array. +The .forEach method throws away return values and will mutate the current array. + + 2. What is the difference between a function and a method? +A function performs a task or calculates a value. +A method IS a function that is the property of an object. + + 3. What is closure? +Closure is a function and all of its lexical environment. + 4. Describe the four rules of the 'this' keyword. +1. Global Binding +When in the global scope, the value of “this” will be the window/console Object; +2. Implicit Binding + Whenever a function is called by a method inside of an object, the object left of the dot gets ‘this’. +3. New Binding + Whenever a constructor function is used, ‘this’ refers to the specific instance of the object that is created and returned by the constructor function. +4. Explicit Binding + 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 illuminates the need for the parent call inside the constructor and automatically binds the parent to the child. + ## Project Set up Follow these steps to set up and work on your project: From 28f9af3776a74f334f04a4ac1be36e606dfb5d60 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Fri, 1 May 2020 23:00:13 -0500 Subject: [PATCH 11/19] working on Functions but not time to finish --- challenges/functions.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/challenges/functions.js b/challenges/functions.js index 6e3688bfcc..d488f81847 100644 --- a/challenges/functions.js +++ b/challenges/functions.js @@ -6,6 +6,9 @@ * The last parameter accepts a callback * 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(); @@ -13,6 +16,15 @@ * Create a function named multiply that returns the product of two numbers * 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, cb) { + return cb(consume(a + b)); +} +function multiply(a, b, cb) { + return cb(consume(a * b)); +} +function greeting(a, b, cb) { + return cb(consume(`Hello ${a + b}, nice to meet you!`)); +} /* Step 3: Check your work by un-commenting the following calls to consume(): */ From cf07440cc087b0c827b07e3c05185c5c31c27fa4 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Mon, 4 May 2020 20:05:55 -0500 Subject: [PATCH 12/19] finished Objects-Arrays request 4 --- challenges/objects-arrays.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index 46f8618aca..a882b2f874 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -147,7 +147,9 @@ The zoos need to know their total animal population across the United States. Fi */ const populationTotal = 0; -zooAnimals.population.reduce(cb, populationTotal) +zooAnimals.reduce(accumulator, currentIndex, cb => { + accumulator += currentIndex.population +}, 0); console.log(populationTotal); From d854b11ced301e732c0ca2381379f0db4ba12705 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Mon, 4 May 2020 20:20:08 -0500 Subject: [PATCH 13/19] finished functions.js file tasks --- challenges/functions.js | 7 ++++--- challenges/objects-arrays.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/challenges/functions.js b/challenges/functions.js index d488f81847..8e520b8f1b 100644 --- a/challenges/functions.js +++ b/challenges/functions.js @@ -28,14 +28,15 @@ function greeting(a, b, cb) { /* 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! // ==== Closures ==== // Explain in your own words why nestedfunction can access the variable internal. +// Since the nestedFunction is nested inside the myFunction, both nestedFunction and variable internal are in the same function scope which makes it possible to access one another // Explanation: diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index a882b2f874..8d7b5739b6 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -147,7 +147,7 @@ The zoos need to know their total animal population across the United States. Fi */ const populationTotal = 0; -zooAnimals.reduce(accumulator, currentIndex, cb => { +zooAnimals.reduce(accumulator, currentIndex, => { accumulator += currentIndex.population }, 0); console.log(populationTotal); From c8ffb540d7b626ae9d5d12b5b2725818f4298142 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Mon, 4 May 2020 20:34:03 -0500 Subject: [PATCH 14/19] finished Prototypes.js file tasks --- challenges/prototypes.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/challenges/prototypes.js b/challenges/prototypes.js index 4cafc33e95..f7dcbd70fb 100644 --- a/challenges/prototypes.js +++ b/challenges/prototypes.js @@ -6,28 +6,41 @@ Create a constructor function named CuboidMaker that accepts properties for length, width, and height */ +function CuboidMaker(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 */ +CuboidMaker.prototype.volume = function (length, width, height) { + return 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. + Create another method using CuboidMaker's prototype that returns the surface area of a given cuboid's length, width, and height. Formula for cuboid surface area of a cube: 2 * (length * width + length * height + width * height) */ +CuboidMaker.prototype.sArea = function (length, width, height) { + return (length * width) + (length * height) + (width * 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. + Add properties and values of length: 4, width: 5, and height: 5 to cuboid. */ +const cuboid = new CuboidMaker(4, 5, 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.volume()); // 100 +console.log(cuboid.surfaceArea()); // 130 From 956a76b8a194fdf4618baf2d89cd380c1670f2a3 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Mon, 4 May 2020 21:00:42 -0500 Subject: [PATCH 15/19] finished Classes.js file tasks + stretch --- challenges/classes.js | 36 ++++++++++++++++++++++++++++++++---- challenges/prototypes.js | 2 +- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/challenges/classes.js b/challenges/classes.js index 992e39dc0b..1839a4865a 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -1,7 +1,35 @@ // 1. Copy and paste your prototype in here and refactor into class syntax. - +class CuboidMaker { + constructor(length, width, height) { + this.length = length; + this.width = width; + this.height = height; + } + volume() { + return this.length * this.width * this.height; + } + surfaceArea() { + return (this.length * this.width) + (this.length * this.height) + (this.width * this.height); + } +} // 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 -// 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(length, width, height) { + super(length, width, height) + this.length = length; + this.width = width; + this.height = height; + } + volume() { + return this.length * this.width * this.height; + } + surfaceArea() { + return (this.length * this.width) * 6; + } +} +console.log(CuboidMaker.volume(5, 5, 5)); +console.log(CuboidMaker.surfaceArea(5, 5)); \ No newline at end of file diff --git a/challenges/prototypes.js b/challenges/prototypes.js index f7dcbd70fb..6f06259e02 100644 --- a/challenges/prototypes.js +++ b/challenges/prototypes.js @@ -28,7 +28,7 @@ CuboidMaker.prototype.volume = function (length, width, height) { Formula for cuboid surface area of a cube: 2 * (length * width + length * height + width * height) */ -CuboidMaker.prototype.sArea = function (length, width, height) { +CuboidMaker.prototype.surfaceArea = function (length, width, height) { return (length * width) + (length * height) + (width * height); } From b51bf060eb3e10c63282e307f6d68fda1286e70b Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Mon, 4 May 2020 22:42:54 -0500 Subject: [PATCH 16/19] finished all MVP tasks --- challenges/classes.js | 4 ++-- challenges/functions.js | 14 +++++++------- challenges/objects-arrays.js | 5 ++--- challenges/prototypes.js | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/challenges/classes.js b/challenges/classes.js index 1839a4865a..1970b2578b 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -31,5 +31,5 @@ class CubeMaker extends CuboidMaker { return (this.length * this.width) * 6; } } -console.log(CuboidMaker.volume(5, 5, 5)); -console.log(CuboidMaker.surfaceArea(5, 5)); \ No newline at end of file +console.log(CubeMaker.volume(5, 5, 5)); +console.log(CubeMaker.surfaceArea(5, 5)); \ No newline at end of file diff --git a/challenges/functions.js b/challenges/functions.js index 8e520b8f1b..78ac6d799c 100644 --- a/challenges/functions.js +++ b/challenges/functions.js @@ -7,7 +7,7 @@ * 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); + return (a, b, cb); } @@ -16,14 +16,14 @@ function consume(a, b, cb) { * Create a function named multiply that returns the product of two numbers * 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, cb) { - return cb(consume(a + b)); +function add(a, b) { + return add(a + b); } -function multiply(a, b, cb) { - return cb(consume(a * b)); +function multiply(a, b) { + return multiply(a * b); } -function greeting(a, b, cb) { - return cb(consume(`Hello ${a + b}, nice to meet you!`)); +function greeting(a, b) { + return greeting(`Hello ${a + b}, nice to meet you!`); } diff --git a/challenges/objects-arrays.js b/challenges/objects-arrays.js index 8d7b5739b6..e6b3d12463 100644 --- a/challenges/objects-arrays.js +++ b/challenges/objects-arrays.js @@ -146,9 +146,8 @@ 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; -zooAnimals.reduce(accumulator, currentIndex, => { - accumulator += currentIndex.population +const populationTotal = zooAnimals.reduce((accumulator, currentIndex) => { + return accumulator += currentIndex.population }, 0); console.log(populationTotal); diff --git a/challenges/prototypes.js b/challenges/prototypes.js index 6f06259e02..06a0087dbb 100644 --- a/challenges/prototypes.js +++ b/challenges/prototypes.js @@ -19,7 +19,7 @@ function CuboidMaker(length, width, height) { Formula for cuboid volume: length * width * height */ CuboidMaker.prototype.volume = function (length, width, height) { - return length * width * height; + return this.length * this.width * this.height; } @@ -29,7 +29,7 @@ CuboidMaker.prototype.volume = function (length, width, height) { Formula for cuboid surface area of a cube: 2 * (length * width + length * height + width * height) */ CuboidMaker.prototype.surfaceArea = function (length, width, height) { - return (length * width) + (length * height) + (width * height); + return ((this.length * this.width) + (this.length * this.height) + (this.width * this.height)) * 2; } From 5c9807c921bffc07d04ecc51491df7a411b92b09 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Tue, 5 May 2020 11:44:02 -0500 Subject: [PATCH 17/19] All but 1 file fixable --- challenges/classes.js | 11 ++++------- challenges/functions.js | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/challenges/classes.js b/challenges/classes.js index 1970b2578b..eb7f8c7395 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -1,5 +1,5 @@ // 1. Copy and paste your prototype in here and refactor into class syntax. -class CuboidMaker { +class CuboidMaker2 { constructor(length, width, height) { this.length = length; this.width = width; @@ -13,20 +13,17 @@ class CuboidMaker { } } // Test your volume and surfaceArea methods by uncommenting the logs below: -console.log(cuboid.volume()); // 100 -console.log(cuboid.surfaceArea()); // 130 +console.log(CuboidMaker2.volume()); // 100 +console.log(CuboidMaker2.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. -class CubeMaker extends CuboidMaker { +class CubeMaker extends CuboidMaker2 { constructor(length, width, height) { super(length, width, height) this.length = length; this.width = width; this.height = height; } - volume() { - return this.length * this.width * this.height; - } surfaceArea() { return (this.length * this.width) * 6; } diff --git a/challenges/functions.js b/challenges/functions.js index 78ac6d799c..21624f0d0a 100644 --- a/challenges/functions.js +++ b/challenges/functions.js @@ -7,7 +7,7 @@ * The consume function should return the invocation of cb, passing a and b into cb as arguments */ function consume(a, b, cb) { - return (a, b, cb); + return cb(a, b); } @@ -17,13 +17,13 @@ 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 add(a + b); + return a + b; } function multiply(a, b) { - return multiply(a * b); + return a * b; } function greeting(a, b) { - return greeting(`Hello ${a + b}, nice to meet you!`); + return `Hello ${a + b}, nice to meet you!`; } From 8804e98113af049cc3eb71ec6f3f74def021ba70 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Tue, 5 May 2020 11:57:32 -0500 Subject: [PATCH 18/19] found equation issue, but function prob unfixable --- challenges/classes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenges/classes.js b/challenges/classes.js index eb7f8c7395..3dd6268f29 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -9,7 +9,7 @@ class CuboidMaker2 { return this.length * this.width * this.height; } surfaceArea() { - return (this.length * this.width) + (this.length * this.height) + (this.width * this.height); + return ((this.length * this.width) + (this.length * this.height) + (this.width * this.height)) * 2; } } // Test your volume and surfaceArea methods by uncommenting the logs below: From 4665172cde4fa91b49a7d28371746adeed9ee5c4 Mon Sep 17 00:00:00 2001 From: JenVest2020 Date: Tue, 5 May 2020 19:46:19 -0500 Subject: [PATCH 19/19] final fix --- challenges/classes.js | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/challenges/classes.js b/challenges/classes.js index 3dd6268f29..4d54bb3b7d 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -12,21 +12,27 @@ class CuboidMaker2 { return ((this.length * this.width) + (this.length * this.height) + (this.width * this.height)) * 2; } } -// Test your volume and surfaceArea methods by uncommenting the logs below: -console.log(CuboidMaker2.volume()); // 100 -console.log(CuboidMaker2.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. -class CubeMaker extends CuboidMaker2 { +class Cuboid2 extends CuboidMaker2 { constructor(length, width, height) { super(length, width, height) - this.length = length; - this.width = width; - this.height = height; - } - surfaceArea() { - return (this.length * this.width) * 6; } } -console.log(CubeMaker.volume(5, 5, 5)); -console.log(CubeMaker.surfaceArea(5, 5)); \ No newline at end of file +let squared = new Cuboid2(4, 5, 5); +// Test your volume and surfaceArea methods by uncommenting the logs below: +console.log(squared.volume()); // 100 +console.log(squared.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. +// class CubeMaker extends CuboidMaker2 { +// constructor(length, width, height) { +// super(length, width, height) +// this.length = length; +// this.width = width; +// this.height = height; +// } +// surfaceArea() { +// return (this.length * this.width) * 6; +// } +// } +// console.log(CubeMaker.volume(5, 5, 5)); +// console.log(CubeMaker.surfaceArea(5, 5)); \ No newline at end of file