Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ Demonstrate your understanding of this week's concepts by answering the followin
Edit this document to include your answers after each question. Make sure to leave a blank line above and below your answer so it is clear and easy to read by your project manager

1. Describe the biggest difference between `.forEach` & `.map`.

.map returns and array
2. What is the difference between a function and a method?

a method is inside of a function
3. What is closure?

closure is a concept whereby a block of code can prevent another block of code from seeing it's values
4. Describe the four rules of the 'this' keyword.

1) global - this = Window
2) Inplicit - Whenever a function is called by a preceding dot, the object before that dot is 'this'
3) New - 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 - Whenever the .call or .apply or .bind is used 'this' is explicitly defined.
5. Why do we need super() in an extended class?
To establish a connection to 'this'

## Project Set up

Expand All @@ -53,7 +57,7 @@ Follow these steps to set up and work on your project:

Follow these steps for completing your project:

- [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo).
- [ x] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo).
- [ ] Add your Project Manager as a Reviewer on the Pull-request
- [ ] PM then will count the HW as done by merging the branch back into master.

Expand All @@ -65,11 +69,11 @@ Your finished project must include all of the following requirements:
**Pro tip for this challenge: If something seems like it isn't working locally, copy and paste your code up to codepen and take another look at the console.**

## Task 1: Objects and Arrays
Test your knowledge of objects and arrays.
Test your knowledge of objects and arrays.
* [ ] Use the [objects-arrays.js](challenges/objects-arrays.js) link to get started. Read the instructions carefully!

## Task 2: Functions
This challenge takes a look at callbacks and closures as well as scope.
This challenge takes a look at callbacks and closures as well as scope.
* [ ] Use the [functions.js](challenges/functions.js) link to get started. Read the instructions carefully!

## Task 3: Prototypes
Expand Down
1 change: 1 addition & 0 deletions challenges/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ const maker = new CubeMaker({

maker.surface(5,8,4, "square inches");
maker.volume(5,8,4, "square inches");
//
1 change: 1 addition & 0 deletions challenges/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ function myFunction() {
nestedFunction();
}
myFunction();
//
24 changes: 11 additions & 13 deletions challenges/objects-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,29 +161,27 @@ console.log(lowerCase);
The zoos are concenred about animals with a lower population count. Find out which animals have a population less than 5.

*/
const largerPopulation = zooAnimals.filter((population) => {
if ( population <= 5 ) {
zooAnimals.animal_name.push();
const largerPopulation = [];
for ( let i = 0; i < zooAnimals.length; i++ ) {
if ( zooAnimals[i].population < 5 ) {
largerPopulation.push(zooAnimals[i].animal_name);
}
});

}
console.log(largerPopulation);


/* 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.

*/
let populationTotal = zooAnimals.reduce((populationTotal, population) => {
populationTotal += population;
}, 0);

console.log(populationTotal);


const totalPopulation = zooAnimals.reduce((total, val) => {
return total += val.population;
}, 0);
console.log(totalPopulation);
/*

Stretch: If you haven't already, convert your array method callbacks into arrow functions.

*/

//
45 changes: 34 additions & 11 deletions challenges/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,63 @@
/* == Step 1: Base Constructor ==
Create a constructor function named CuboidMaker that accepts properties for length, width, and height
*/
class CuboidMaker {
constructor(args) {
this.width = args.width;
this.length = args.length;
this.height = args.height;
}
volume() {
return `I'm building a Cuboid Volume from args ${this.width} ${this.height} ${this.length} this.length * this.width * this.height`;
function CuboidMaker(length, width, height) {
constructor(this.length, this.width, this.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
CuboidMaker.prototype.volume
Formula for cuboid volume: length * width * height
*/
CuboidMaker.prototype.volume = function(length, width, height) {
return(length * width * height);
}
const cuboid = Object.create(CuboidMaker.prototype);
/* == 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.

Formula for cuboid surface area of a cube: 2 * (length * width + length * height + width * height)
*/
CuboidMaker.prototype.surfaceArea = function(length, width, height) {
return( 2 * ((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.
*/

// Test your volume and surfaceArea methods by uncommenting the logs below:
console.log(cuboid.volume(5, 5, 5)); // 100
console.log(cuboid.surfaceArea(5, 5, 5)); // 130



/* == 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
*/

/* == 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)
*/


/* == 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.
*/

// Test your volume and surfaceArea methods by uncommenting the logs below:
// console.log(cuboid.volume()); // 100
// console.log(cuboid.surfaceArea()); // 130


//