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
41 changes: 29 additions & 12 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,21 +29,30 @@ 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`.
forEach Is a built-in iterator that performs for each 'item'/'value' a callback's body. It return: undefined.
.map() Is an iterator that performs a given funtionality passed as a callback on each 'item'/'value'. This method return a new array with the values returned by the callback.

2. What is the difference between a function and a method?
Functions are objects taht are no tide to any other object, and methods are tied to another Object.

3. What is closure?
A closure is what a function can have access to.

4. Describe the four rules of the 'this' keyword.
A 'new' brand created Object. At Objects instantiation when the 'new' keyword is used.
An Object Explicitly when it invokes using either: .call, .bind or .apply
An Object Implicitly when it is invoked from this Object as a method with the 'dot' notations.
Global object (The window in browsers) when neither of the other cases is applied.

5. Why do we need super() in an extended class?
Is the keyword that allow us to 'refer'/'call' the class from which is inherit.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The super() is used to access and call functions on an object's parent. When used in a constructor, the super keyword appears alone and must be used before the this keyword is used.


### Git Set up

* [ ] Fork the project into your GitHub user account
* [ ] Clone the forked project into a directory on your machine
* [ ] 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
- [ ] Fork the project into your GitHub user account
- [ ] Clone the forked project into a directory on your machine
- [ ] 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

## Minimum Viable Product

Expand All @@ -52,23 +61,31 @@ 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.

- [ ] 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.

- [ ] 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!

- [ ] 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!

- [ ] 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.

## Stretch Problems

There are a few stretch problems found throughout the files, don't work on them until you are finished with MVP requirements!
There are a few stretch problems found throughout the files, don't work on them until you are finished with MVP requirements!
39 changes: 36 additions & 3 deletions challenges/classes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
// 1. Copy and paste your prototype in here and refactor into class syntax.
class CuboidMaker {
constructor(attributes) {
this.length = attributes.length;
this.width = attributes.width;
this.height = attributes.height;
}
volume() {
return this.length * this.width * this.height;
}
surfaceArea() {
return (
2 *
(this.length * this.width +
this.length * this.height +

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what you have done is fine but yo can/should also use brackets to mark the separation between 2 operator. so, it's easier to read. you can do something like

return 2 * ((this.length * this.width) + (this.length * this.height) + (this.width * 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.
// 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(attributes) {
super(attributes, attributes, attributes);
}
volume() {
return Math.pow(this.length || this.height || this.width, 3);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also use exponential operator ** to raise the power. so, you can also do something like

return this.length ** 3

}
surfaceArea() {
return Math.pow(this.length || this.height || this.width, 2) * 6;
}
}

const cube = new CubeMaker(5, 5, 5);
console.log(cube.volume());
console.log(cube.surfaceArea());
51 changes: 29 additions & 22 deletions challenges/functions.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
// ==== 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
*/
const consume = (param1, param2, cb) => cb(param1, param2);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great use of arrow function. pretty neat.


/* 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(param1, param2) {
return param1 + param2;
}
function multiply(param1, param2) {
return param1 * param2;
}
function greeting(frist, last) {
return `Hello ${frist} ${last}, nice to meet you`;
}

/* 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(2, 2, add); // 4
consume(10, 16, multiply); // 160
consume("Mary", "Poppins", greeting); // Hello Mary Poppins, nice to meet you!

// ==== Closures ====
// ==== Closures ====

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

// Explanation:

// myFunction() is called from the Global Scope returning nestedFunction().
// nestedFunction() is 'executed' whitin myFunction, thus it has access to myFunction()'s inner and surrounding scopes
// Explanation:

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

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

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