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
12 changes: 12 additions & 0 deletions .idea/Sprint-Challenge--JavaScript.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

189 changes: 189 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions ANSWERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
1. Describe the biggest difference between `.forEach` & `.map`.

**forEach is used to apply functions or changes to an existing array. .map does the same but returns a new array and does not alter the original array.**

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

**Functions and methods both are functions in JavaScript. A method is just a function which is a property of an object.**

3. What is closure?

**Closure is a feature in JavaScript where an inner function has access to the outer (enclosing) function's variables — a scope chain. The closure has three scope chains: it has access to its own scope — variables defined between its curly brackets. it has access to the outer function's variables.**
4. Describe the four rules of the 'this' keyword.

**Global Binding - 'this' used outside of an object will refer to the window object.**
**Implicit Binding - object that invokes the function is referred to as this. "objectForThis.this"**
**New Binding - this refers to the copy built with the constructor function**
**Explicit Binding - When using call or apply, this will refer to the object that inheritance is being received from.**

5. Why do we need super() in an extended class?

**A new object is created and this references the new object that was created. super() allows us to access/call functions on an object's parent. It is used to avoid dupllicating the parts of the constructor that are similar.**













![Adam+Savage](https://user-images.githubusercontent.com/11761437/57549710-4550e800-7332-11e9-9370-ee952c21a160.jpg)




56 changes: 53 additions & 3 deletions challenges/classes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
// 1. Copy and paste your prototype in here and refactor into class syntax.

class CuboidMaker {
constructor(properties) {
this.length = properties.length;
this.width = properties.width;
this.height = properties.height;
}

volume() {
return this.length * this.width * this.height;
}


surfaceArea() {
return 2 * (this.length * this.width + this.length * this.height + this.width * this.height);
}

}


const 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.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

class CubeMaker extends CuboidMaker {
constructor(cubeAttributes) {
super(cubeAttributes);

}
cubeVolume() {
let total = this.length * this.height * this.width;
return total;
}
cubeSurfaceArea() {
let total = 6 * (Math.pow(this.cubeVolume(), 2));
return total;
}
}

const cube = new CubeMaker({
length: 5,
width: 5,
height: 5,
});

// 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.
console.log(cube.cubeVolume());
console.log(cube.cubeSurfaceArea());
Loading