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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
56 changes: 38 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Commit your code regularly and meaningfully. This helps both you (in case you ev

## Description

You will notice there are several JavaScript files being brought into the index.html file. Each of those files contain JavaScript problems you need to solve. If you get stuck on something, skip over it and come back to it later.
You will notice there are several JavaScript files being brought into the index.html file. Each of those files contain JavaScript problems you need to solve. If you get stuck on something, skip over it and come back to it later.

In meeting the minimum viable product (MVP) specifications listed below, you should have a console full of correct responses to the problems given.

Expand All @@ -29,34 +29,46 @@ 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`.
These two are very similar but share a key difference. .map creates a new array. Where .forEach does not. Both execute a function once for each element in an array.

2. What is the difference between a function and a method?
I think they're both technically functions. However, a method is a function which is a PROPERTY of an object.

3. What is closure?
Closure is the act of creating a function within a function and limiting it's access or scope to ONLY what is inside the parent function.

4. Describe the four rules of the 'this' keyword.

1. Global Scope
This is literally JS. Every object in JS in within this scope if 'this' is called.
2. Implicit Binding
When a function is called by a preceding dot the object before that dot is 'this'.
3. Explicit Binding
This overrides the 'new' binding by explicitly telling the function which object's 'this' we would like to access. Commonly with .call or .apply. I assume super() does the same thing?
4. New Binding
Whenever we call on a function inside an object with 'new' this references that object.

5. Why do we need super() in an extended class?
The super function is what gives our extends context. Without the super, the class does not know what to do with the extended object.

## Project Set up

Follow these steps to set up and work on your project:

- [ ] Create a forked copy of this project.
- [ ] Add PM 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 `<firstName-lastName>`.
- [ ] 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 `<firstName-lastName>`.
- [x] Create a forked copy of this project.
- [x] Add PM 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 `<firstName-lastName>`.
- [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 `<firstName-lastName>`.

Follow these steps for completing your project:

- [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo).
- [ ] 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.

- [ ] PM then will count the HW as done by merging the branch back into master.

## Minimum Viable Product

Expand All @@ -65,20 +77,28 @@ 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.
* [ ] Use the [objects-arrays.js](challenges/objects-arrays.js) link to get started. Read the instructions carefully!

Test your knowledge of objects and arrays.

- [x] 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.
* [ ] Use the [functions.js](challenges/functions.js) link to get started. Read the instructions carefully!

This challenge takes a look at callbacks and closures as well as scope.

- [x] Use the [functions.js](challenges/functions.js) link to get started. Read the instructions carefully!

## Task 3: 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 4: 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.

Expand Down
37 changes: 32 additions & 5 deletions challenges/classes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
// 1. Copy and paste your prototype in here and refactor into class syntax.
class CuboidMaker {
constructor(sizes) {
this.length = sizes.length;
this.width = sizes.width;
this.height = sizes.height;
}

// Test your volume and surfaceArea methods by uncommenting the logs below:
// console.log(cuboid.volume()); // 100
// console.log(cuboid.surfaceArea()); // 130
volume() {
return this.length * this.width * this.height;
}

// 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.
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 me
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.
58 changes: 38 additions & 20 deletions challenges/functions.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
// ==== Callbacks ====
// ==== Callbacks ====

/* Step 1: Create a higher-order function that accepts a callback
* Create a higher-order function named consume that can take 3 parameters.
* The first two parameters can accept any argument
* The last parameter accepts a callback
* In the body of the function return the callback with the two parameters that you created
*/

* Create a higher-order function named consume that can take 3 parameters.
* The first two parameters can accept any argument
* The last parameter accepts a callback
* In the body of the function return the callback with the two parameters that you created
*/
function consume(num1, num2, cb) {
return cb(num1, num2);
}

/* Step 2: Create several functions to callback with consume();
* Create a function named add that returns the sum of two numbers
* 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!"
*/
* Create a function named add that returns the sum of two numbers
* 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(x, y) {
console.log("add", x + y);
}

/* Step 3: Check your work by un-commenting the following calls to consume(): */
// consume(2,2,add); // 4
// consume(10,16,multiply); // 160
// consume("Mary","Poppins", greeting); // Hello Mary Poppins, nice to meet you!
consume(1, 2, add);

function multiply(x, y) {
console.log("multiply", x * y);
}

// ==== Closures ====
consume(2, 3, multiply);

// Explain in your own words why `nestedfunction()` can access the variable `internal`.
function greeting(firstName, lastName) {
console.log("greeting:", `Hello ${firstName} ${lastName}, nice to meet you!`);
}

consume("Ben", "Feole", greeting);
// LOL added checks before step 3. woops.

/* Step 3: Check your work by un-commenting the following calls to consume(): */
consume(2, 2, add); // 4
consume(10, 16, multiply); // 160
consume("Mary", "Poppins", greeting); // Hello Mary Poppins, nice to meet you!

// ==== Closures ====

// Explanation:
// Explain in your own words why `nestedfunction()` can access the variable `internal`.

// Explanation: nestedfunction is INSIDE myFunction, so it will have access to anything that myFunction has access too.

const external = "I'm outside the function";

Expand All @@ -36,7 +54,7 @@ function myFunction() {

function nestedFunction() {
console.log(internal);
};
}
nestedFunction();
}
myFunction();
myFunction();
Loading