From d1811792267f62e4e6b6d660611ba0412a0e030c Mon Sep 17 00:00:00 2001 From: Chris Elles Date: Mon, 17 Aug 2020 13:39:58 +1200 Subject: [PATCH 1/7] first push --- README.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cc6d6902fb..4118c7a78f 100644 --- a/README.md +++ b/README.md @@ -26,24 +26,44 @@ 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) +.map on an array returns a new arra with the result of the callback function for each element of the original array. + +.foreach also covers the callback function for each element of the array, but it does not return a new array like .map does. + 2. Explain the difference between a callback and a higher order function. +A higher order functions take another function as argument. Callbacl is a function that is passed to another function for it to be invoked inside of it. + +A higher order function receives a function as argument. Callback functions are passed as arguments to other functions. + 3. What is closure? +Closure is the combination of a function bundled together(enclosed) with references to its surrounding state. Closures are created everytime a function is created, at function creation time. + 4. Describe the four rules of the 'this' keyword. +1)Global Scope binding: when 'this' is used outside of any specific object. + +2)New binding: when 'new' is used with constructors to build new objects. + +3)Explicit binding: when using apply and call where we chose some object for some fucntion to copy parent's property. + +4)Implicit binding: when 'this' is used with a specific declared object. + 5. Why do we need super() in an extended class? +when creating a child class of a parent class. It is for the child class to access the methods and properties of the parent class for the child class to access the functions of the parent class. + ### 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. +- [ ] 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 - [ ] Implement the project on your Branch, committing changes regularly. - [ ] Push commits: git push origin ``. From 7d0e3e2a43a3abeabd90f9be019d7a5410d44796 Mon Sep 17 00:00:00 2001 From: Chris Elles Date: Mon, 17 Aug 2020 14:07:18 +1200 Subject: [PATCH 2/7] closure --- challenges/closure.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/challenges/closure.js b/challenges/closure.js index 101d68e553..53da5794bb 100644 --- a/challenges/closure.js +++ b/challenges/closure.js @@ -17,8 +17,24 @@ function myFunction() { myFunction(); // Explanation: +/* nestedFunction is the Child of the myFunction Parent function. The Child function(nested function)can reach the Parent function to get the variable's value. Closure is made as the 'internal' variable is available in the Parent function's scope. And the Child function is able to reach out to the Parent function when the variable is not defined within it. +*/ /* 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 sumation(number) { + let sum=0; + if(number>=1) { + sum=number+sumation(number-1); + } return sum; +} +console.log("Counter: ") +console.log(sumation(4)); +console.log(sumation(3)); +console.log(sumation(2)); +console.log(sumation(10)); +console.log(sumation(100)); + \ No newline at end of file From 96504dc77e4471be768d7df6790dcbc72a165630 Mon Sep 17 00:00:00 2001 From: Chris Elles Date: Mon, 17 Aug 2020 14:44:12 +1200 Subject: [PATCH 3/7] Arrays & Callbacks --- challenges/arrays-callbacks.js | 44 ++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index 12af878ceb..bb340d6fc0 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -21,7 +21,12 @@ The zoos want to display both the scientific name and the animal name in front o */ const displayNames = []; +console.log("Animal Name and Scientific Name"); +zooAnimals.forEach((item)=>{ + displayNames.push(`Name: ${item.animal_name}, Scientific: ${item.scientific_name}`); +}) console.log(displayNames); +console.log(typeof(displayNames[2])); /* Request 2: .map() @@ -29,7 +34,10 @@ The zoos need a list of all their animal's names (animal_name only) converted to */ -const lowCaseAnimalNames = []; +console.log("Animal Name in lower case: "); +const lowCaseAnimalNames =zooAnimals.map((item) =>{ + return(`${item.animal_name.toLowerCase()}`); +}) console.log(lowCaseAnimalNames); /* Request 3: .filter() @@ -37,15 +45,26 @@ 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 = []; + +console.log("Animals with Population <5"); +const lowPopulationAnimals=zooAnimals.filter((item)=>{ + return(item.population<5); +}) + console.log(lowPopulationAnimals); +console.log(typeof(lowCaseAnimalNames)); /* Request 4: .reduce() 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. */ + let populationTotal = 0; +console.log("Total Animal Population: "); +populationTotal=zooanimals.reduce((accum,currentValue) =>{ + return (accum += currentValue.population); +},0); console.log(populationTotal); @@ -58,6 +77,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 @@ -65,11 +87,23 @@ console.log(populationTotal); * 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(numbera,numberb) { + return(numbera+numberb); +} + +function multiply(numbera,numberb) { + return(numbera*numberb); +} + +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 -// 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! From 6c69bc14524870686393ae29762aee6204b23028 Mon Sep 17 00:00:00 2001 From: Chris Elles Date: Mon, 17 Aug 2020 15:17:51 +1200 Subject: [PATCH 4/7] Prototypes --- challenges/prototypes.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/challenges/prototypes.js b/challenges/prototypes.js index 4cafc33e95..8b0622d84a 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(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 @@ -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,19 @@ 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.width*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(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 f27791fb9efcfbf9c1e708b7a1255658894db2c8 Mon Sep 17 00:00:00 2001 From: Chris Elles Date: Mon, 17 Aug 2020 15:45:13 +1200 Subject: [PATCH 5/7] Classes --- challenges/classes.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/challenges/classes.js b/challenges/classes.js index 992e39dc0b..5bf430ad0e 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -1,7 +1,22 @@ // 1. Copy and paste your prototype in here and refactor into class syntax. +function CuboidMaker(length, width, height) { + this.length=length; + this.width=width; + this.height=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 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 // 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 ca3c586719bcc07cdecdf70b9832aa198d86da80 Mon Sep 17 00:00:00 2001 From: Chris Elles Date: Mon, 12 Oct 2020 16:53:35 +1300 Subject: [PATCH 6/7] OCT/20 Final --- README.md | 26 +++--- challenges/arrays-callbacks.js | 141 ++++++++++++++++++++++----------- challenges/classes.js | 48 ++++++++--- challenges/closure.js | 25 +++--- challenges/prototypes.js | 28 ++++--- 5 files changed, 177 insertions(+), 91 deletions(-) diff --git a/README.md b/README.md index 4118c7a78f..4a79fbefa7 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,15 @@ 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) -.map on an array returns a new arra with the result of the callback function for each element of the original array. +Both .forEach and .map are array methods that accept a callback to execute a set of instructions on each array element. + +.map on an array returns a new array with the result of the callback function for each element of the original array. .foreach also covers the callback function for each element of the array, but it does not return a new array like .map does. 2. Explain the difference between a callback and a higher order function. -A higher order functions take another function as argument. Callbacl is a function that is passed to another function for it to be invoked inside of it. +A higher order functions take another function as argument. Callback is a function that is passed to another function for it to be invoked inside of it. A higher order function receives a function as argument. Callback functions are passed as arguments to other functions. @@ -52,21 +54,21 @@ Closure is the combination of a function bundled together(enclosed) with referen 5. Why do we need super() in an extended class? -when creating a child class of a parent class. It is for the child class to access the methods and properties of the parent class for the child class to access the functions of the parent class. +When creating a child class of a parent class. It is for the child class to access the methods and properties of the parent class for the child class to access the functions of the parent class. ### 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. 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 +- [X] Create a forked copy of this project. +- [ ] Add TL as collaborator on Github. +- [X] Clone your OWN version of Repo (Not Lambda's by mistake!). +- [X] 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 ``. +- [X] Implement the project on your Branch, committing changes regularly. +- [X] Push commits: git push origin ``. @@ -81,7 +83,7 @@ Your finished project must include all of the following requirements: Test your knowledge of advanced array methods and callbacks. * [ ] Use the [arrays-callbacks.js](challenges/arrays-callbacks.js) link to get started. Read the instructions carefully! -#### Task B: Closure +#### Task B: Closure DONE This challenge takes a look at closures as well as scope. * [ ] Use the [closure.js](challenges/closure.js) link to get started. Read the instructions carefully! @@ -106,6 +108,6 @@ There are a few stretch problems found throughout the files, don't work on them Follow these steps for completing your project: -- [ ] Submit a Pull-Request to merge Branch into master (student's Repo). +- [X] Submit a Pull-Request to merge Branch into master (student's Repo). - [ ] Add your team lead as a Reviewer on the Pull-request - [ ] TL then will count the HW as done by merging the branch back into master. diff --git a/challenges/arrays-callbacks.js b/challenges/arrays-callbacks.js index bb340d6fc0..528aa4a072 100644 --- a/challenges/arrays-callbacks.js +++ b/challenges/arrays-callbacks.js @@ -3,30 +3,82 @@ // 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. const zooAnimals = [ - { animal_name: "Jackal, asiatic", population: 5, scientific_name: "Canis aureus", state: "Kentucky" }, - { animal_name: "Screamer, southern", population: 1, scientific_name: "Chauna torquata", state: "Alabama" }, - { animal_name: "White spoonbill", population: 8, scientific_name: "Platalea leucordia", state: "Georgia" }, - { animal_name: "White-cheeked pintail", population: 1, scientific_name: "Anas bahamensis", state: "Oregon" }, - { animal_name: "Black-backed jackal", population: 2, scientific_name: "Canis mesomelas", state: "Washington" }, - { animal_name: "Brolga crane", population: 9, scientific_name: "Grus rubicundus", state: "New Mexico" }, - { animal_name: "Common melba finch", population: 5, scientific_name: "Pytilia melba", state: "Pennsylvania" }, - { animal_name: "Pampa gray fox", population: 10, scientific_name: "Pseudalopex gymnocercus", state: "Connecticut" }, - { animal_name: "Hawk-eagle, crowned", population: 10, scientific_name: "Spizaetus coronatus", state: "Florida" }, - { animal_name: "Australian pelican", population: 5, scientific_name: "Pelecanus conspicillatus", state: "West Virginia" }, + { + animal_name: "Jackal, asiatic", + population: 5, + scientific_name: "Canis aureus", + state: "Kentucky", + }, + { + animal_name: "Screamer, southern", + population: 1, + scientific_name: "Chauna torquata", + state: "Alabama", + }, + { + animal_name: "White spoonbill", + population: 8, + scientific_name: "Platalea leucordia", + state: "Georgia", + }, + { + animal_name: "White-cheeked pintail", + population: 1, + scientific_name: "Anas bahamensis", + state: "Oregon", + }, + { + animal_name: "Black-backed jackal", + population: 2, + scientific_name: "Canis mesomelas", + state: "Washington", + }, + { + animal_name: "Brolga crane", + population: 9, + scientific_name: "Grus rubicundus", + state: "New Mexico", + }, + { + animal_name: "Common melba finch", + population: 5, + scientific_name: "Pytilia melba", + state: "Pennsylvania", + }, + { + animal_name: "Pampa gray fox", + population: 10, + scientific_name: "Pseudalopex gymnocercus", + state: "Connecticut", + }, + { + animal_name: "Hawk-eagle, crowned", + population: 10, + scientific_name: "Spizaetus coronatus", + state: "Florida", + }, + { + animal_name: "Australian pelican", + population: 5, + scientific_name: "Pelecanus conspicillatus", + state: "West Virginia", + }, ]; +console.log("-ADVANCED ARRAY METHODS-"); +console.log(""); + /* Request 1: .forEach() 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 = []; -console.log("Animal Name and Scientific Name"); -zooAnimals.forEach((item)=>{ - displayNames.push(`Name: ${item.animal_name}, Scientific: ${item.scientific_name}`); -}) -console.log(displayNames); -console.log(typeof(displayNames[2])); +let displayNames = []; + +zooAnimals.forEach((item) => displayNames.push('Name: ${item.animal_name}, Scientific: ${item.scientific_name}') +); +console.log("The answer to Task #1 is: ", displayNames); +console.log(""); /* Request 2: .map() @@ -34,11 +86,9 @@ The zoos need a list of all their animal's names (animal_name only) converted to */ -console.log("Animal Name in lower case: "); -const lowCaseAnimalNames =zooAnimals.map((item) =>{ - return(`${item.animal_name.toLowerCase()}`); -}) -console.log(lowCaseAnimalNames); +const lowCaseAnimalNames = zooAnimals.map((item) => item.animal_name.toLowerCase()); +console.log("The answer to Task #2 is: ", lowCaseAnimalNames); +console.log(""); /* Request 3: .filter() @@ -46,13 +96,9 @@ The zoos are concerned about animals with a lower population count. Using filter */ -console.log("Animals with Population <5"); -const lowPopulationAnimals=zooAnimals.filter((item)=>{ - return(item.population<5); -}) - -console.log(lowPopulationAnimals); -console.log(typeof(lowCaseAnimalNames)); +const lowPopulationAnimals = zooAnimals.filter((item) => item.population < 5); +console.log("The answer to Task #3 is: ", lowPopulationAnimals); +console.log(""); /* Request 4: .reduce() @@ -61,11 +107,13 @@ The zoos need to know their total animal population across the United States. Fi */ let populationTotal = 0; -console.log("Total Animal Population: "); -populationTotal=zooanimals.reduce((accum,currentValue) =>{ - return (accum += currentValue.population); -},0); -console.log(populationTotal); +populationTotal = zooAnimals.reduce((accum, items) => { + return (accum = accum + items.population); +}, 0) +console.log("The answer to Task #4 is: ", populationTotal); +console.log(""); +console.log("-CALL BACKS-"); +console.log(""); // ==== Callbacks ==== @@ -77,8 +125,8 @@ 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); +function consume(a,b,callback) { + return callback(a, b); } /* Step 2: Create several functions to callback with consume(); @@ -87,23 +135,26 @@ 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(numbera,numberb) { - return(numbera+numberb); +function add(a, b) { + return a + b; } -function multiply(numbera,numberb) { - return(numbera*numberb); +function multiply(a, b) { + return a * b; } -function greeting(firstname,lastname){ - return(`Hello ${firstname} ${lastname}, nice to meet you!`); +function greeting(firstName, lastName) { + return 'Hello ${firstName} ${lastName}, nice to meet you.'; } +console.log(""); /* 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("The answer is: ", consume(2, 2, add)); // 4 +console.log(""); +console.log("The answer is: ", consume(10, 16, multiply)); // 160 +console.log(""); +console.log("The answer is: ", consume("Mary", "Poppins", greeting)); // Hello Mary Poppins, nice to meet you! diff --git a/challenges/classes.js b/challenges/classes.js index 5bf430ad0e..ca9f366b64 100644 --- a/challenges/classes.js +++ b/challenges/classes.js @@ -1,22 +1,50 @@ +console.log("-CLASSES-"); +console.log(""); + // 1. Copy and paste your prototype in here and refactor into class syntax. -function CuboidMaker(length, width, height) { - this.length=length; - this.width=width; - this.height=height; +class CuboidMakerX { + constructor(length, width, height) { + this.length = length; + this.width = width; + this.height = height; } volume() { - return(this.length*this.width*this.height); + return this.length * this.width * this.height; } surfaceArea() { - return(2*((this.length*this.width)+(this.length*this.height)+(this.width*this.height))); + return(2 * (this.length * this.width * this.height)); } } - let cuboid=new CuboidMaker(4,5,5); +var cuboid = new CuboidMakerX(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("Volume Task: ", cuboid.volume()); // 100 +console.log(""); +console.log("Surface Area Task: ", cuboid.surfaceArea()); // 130 +console.log(""); + +// 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 CuboidMakerX { + constructor(dimension) { + super(dimension, dimension, dimension); + } + volume() { + return Math.pow(this.width, 3); + } + surfaceArea() { + return 6 * Math.pow(this.width, 2); + } +} + +const myCube = new cubeMaker(4); +console.log("Stretch:") +console.log(""); +console.log(myCube); +console.log(""); +console.log(myCube.volume); +console.log(""); +console.log(myCube.surfaceArea); -// 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 diff --git a/challenges/closure.js b/challenges/closure.js index 53da5794bb..1ab096e188 100644 --- a/challenges/closure.js +++ b/challenges/closure.js @@ -1,3 +1,6 @@ +console.log(""); +console.log("-CLOSURE-"); +console.log(""); // ==== Closures ==== /* Task 1: Study the code below and explain in your own words why nested function can access the variable internal. */ @@ -11,7 +14,7 @@ function myFunction() { function nestedFunction() { console.log(internal); - }; + } nestedFunction(); } myFunction(); @@ -25,16 +28,14 @@ myFunction(); /* 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 sumation(number) { - let sum=0; - if(number>=1) { - sum=number+sumation(number-1); - } return sum; +let counter = 0; +function summation(num) { + for (let i = 0; i <= num; i++) { + counter += i; + } + return counter; } -console.log("Counter: ") -console.log(sumation(4)); -console.log(sumation(3)); -console.log(sumation(2)); -console.log(sumation(10)); -console.log(sumation(100)); + +console.log("A function using closure to get summation of the number 4:", summation(4)); +console.log(""); \ No newline at end of file diff --git a/challenges/prototypes.js b/challenges/prototypes.js index 8b0622d84a..ac53b194db 100644 --- a/challenges/prototypes.js +++ b/challenges/prototypes.js @@ -1,3 +1,5 @@ +console.log("-PROTOTYPES-"); +console.log(""); /* ===== Prototype Practice ===== */ // Task: You are to build a cuboid maker that can return values for a cuboid's volume or surface area. Cuboids are similar to cubes but do not have even sides. Follow the steps in order to accomplish this challenge. @@ -7,9 +9,9 @@ */ function CuboidMaker(length, width, height) { - this.length=length; - this.width=width; - this.height=height; + this.length = length; + this.width = width; + this.height = height; } /* == Step 2: Volume Method == @@ -18,9 +20,10 @@ function CuboidMaker(length, width, height) { Formula for cuboid volume: length * width * height */ -CuboidMaker.prototype.volume=function() { - return(this.length*this.width*this.height); -} +CuboidMaker.prototype.volume = function() { + const formula = this.length * this.width * this.height; + return formula; +}; /* == 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. @@ -28,19 +31,20 @@ CuboidMaker.prototype.volume=function() { 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.width*this.height)+(this.width*this.height))); -} +CuboidMaker.prototype.surfaceArea = function() { + const formula = 2 * (this.length * this.width + this.width * this.height + this.width * this.height); + return formula; +}; /* == 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(4,5,5); +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("The Volume is: ", cuboid.volume()); // 100 +console.log("The Surface Area is: ", cuboid.surfaceArea()); // 130 From 7c50a379ad018d3a1459be476a971d579d952f0d Mon Sep 17 00:00:00 2001 From: Chris Elles Date: Wed, 14 Oct 2020 10:14:14 +1300 Subject: [PATCH 7/7] OCT/20 updated Readme --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4a79fbefa7..a13b6a7e35 100644 --- a/README.md +++ b/README.md @@ -62,11 +62,11 @@ 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! - [X] Create a forked copy of this project. -- [ ] Add TL as collaborator on Github. +- [X] Add TL as collaborator on Github. - [X] Clone your OWN version of Repo (Not Lambda's by mistake!). - [X] 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 +- [X] Create a pull request before you start working on the project requirements. You will continuously push your updates throughout the project. +- [X] You are now ready to build this project with your preferred IDE - [X] Implement the project on your Branch, committing changes regularly. - [X] Push commits: git push origin ``. @@ -81,22 +81,22 @@ Your finished project must include all of the following requirements: #### Task A: Objects and Arrays Test your knowledge of advanced array methods and callbacks. -* [ ] Use the [arrays-callbacks.js](challenges/arrays-callbacks.js) link to get started. Read the instructions carefully! +* [X] Use the [arrays-callbacks.js](challenges/arrays-callbacks.js) link to get started. Read the instructions carefully! #### Task B: Closure DONE This challenge takes a look at closures as well as scope. -* [ ] Use the [closure.js](challenges/closure.js) link to get started. Read the instructions carefully! +* [X] Use the [closure.js](challenges/closure.js) link to get started. Read the instructions carefully! #### Task C: Prototypes Create constructors, bind methods, and create cuboids in this prototypes challenge. -* [ ] Use the [prototypes.js](challenges/prototypes.js) link to get started. Read the instructions carefully! +* [X] Use the [prototypes.js](challenges/prototypes.js) link to get started. Read the instructions carefully! #### Task D: Classes Once you have completed the prototypes challenge, it's time to convert all your hard work into classes. -* [ ] Use the [classes.js](challenges/classes.js) link to get started. Read the instructions carefully! +* [X] Use the [classes.js](challenges/classes.js) link to get started. Read the instructions carefully! In your solutions, it is essential that you follow best practices and produce clean and professional results. Schedule time to review, refine, and assess your work and perform basic professional polishing including spell-checking and grammar-checking on your work. It is better to submit a challenge that meets MVP than one that attempts too much and does not. @@ -109,5 +109,5 @@ There are a few stretch problems found throughout the files, don't work on them Follow these steps for completing your project: - [X] Submit a Pull-Request to merge Branch into master (student's Repo). -- [ ] Add your team lead as a Reviewer on the Pull-request +- [X] Add your team lead as a Reviewer on the Pull-request - [ ] TL then will count the HW as done by merging the branch back into master.