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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ 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`.
They both invoke a function on every item in a given array, however .map will create a new array with the return value, where .forEach works on the parent/original array

2. What is the difference between a function and a method?
A method is a function that is performed from inside an object.

3. What is closure?
A functions ability to access all variables inside of it

4. Describe the four rules of the 'this' keyword.
Window Binding - 'this' called in the global scope refers to the window (or as I like to say 'Active') object

Implicit Binding - When something is called with ., the item refered to to the left of the . will be our 'this' object

New Binding - When a constructor function is used to create an object, 'this' refers to that new object

Explicit Binding - Used when we want to specifically tell javascript what 'this' will refer to

5. Why do we need super() in an extended class?
super() Informs a parent constructor function to watch a childs attributes to fill its own.

## Project Set up

Expand Down
30 changes: 29 additions & 1 deletion challenges/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,32 @@
// 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 CuboidMaker{
constructor(attr){
this.length = attr.length;
this.width = attr.width;
this.height = attr.height;
}

volume(){
return `${this.length * this.width * this.height}`;
}
surfaceArea(){
const lw = this.length*this.width;
const lh = this.length*this.height;
const wh = this.width*this.height;
const area = lw + lh + wh
return area*2;
//still a clunky solution
}
}

const cuboid = new CuboidMaker({
length: 4,
width: 5,
height: 5
});

console.log(cuboid.volume()); // 100
console.log(cuboid.surfaceArea()); //130
22 changes: 18 additions & 4 deletions challenges/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,39 @@
* In the body of the function return the callback with the two parameters that you created
*/

function consume(param1, param2, callback){
callback(param1, param2);
}


/* 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!"
*/

function add(param1, param2){
console.log(`${param1*param2}`);
}
function multiply(param1, param2){
console.log(`${param1*param2}`);
}
function greeting(name, last_name){
console.log(`Hello ${name} ${last_name}, 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 ====

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

// Explanation:
// Explanation: Both variables were declared inside of the parent function and a functions children has access to all variables declared inside of it


const external = "I'm outside the function";
Expand Down
3 changes: 2 additions & 1 deletion challenges/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
<body>
<h1>Sprint Challenge - Check your work in the console!</h1>
</body>
</html>
</html>
<!-- its early and i am tired -->
96 changes: 78 additions & 18 deletions challenges/objects-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@
Use this pattern to create your objects:
object name, diet, weight, length, period
*/
const tyrannosaurus = {
name: `tyrannosaurus`,
diet: `carnivorous`,
weight: `7000kg`,
length: `12m`,
period: `Late Cretaceious`,
roar(){
return `RAWERSRARARWERSARARARRRR!`
}
};

const stegosaurus = {
name: `stegosaurus`,
diet: `herbivorous`,
weight: `2000kg`,
length: `9m`,
period: `Late Jurassic`
};

const velociraptor = {
name: `velociraptor`,
diet: `carnivorous`,
weight: `15kg`,
length: `1.8m`,
period: `Late Cretaceious`
};

// tyrannosaurus, carnivorous, 7000kg, 12m, Late Cretaceious

Expand All @@ -15,20 +41,20 @@
// Using your dinosaur objects, log answers to these questions:

// How much did tyrannosaurus weigh?
console.log();
console.log(tyrannosaurus.weight);

// What was the diet of a velociraptor?
console.log();
console.log(velociraptor.diet);

// How long was a stegosaurus?
console.log();
console.log(stegosaurus.length);

// What time period did tyrannosaurus live in?
console.log();
console.log(tyrannosaurus.period);


// Create a new roar method for the tyrannosaurus. When called, return "RAWERSRARARWERSARARARRRR!" Log the result.
console.log();
console.log(tyrannosaurus.roar());


// ==== Arrays ====
Expand All @@ -49,22 +75,39 @@ const graduates = [{"id":1,"first_name":"Cynde","university":"Missouri Southern
/* Request 1: Create a new array called universities that contains all the univeristies in the graduates array.

Once you have the new array created, sort the universities alphabetically and log the result. */
const universities = [];
console.log(universities)

const univ = [];
for (let i = 0; i < graduates.length; i++) {
univ.push(graduates[i].university)
};
univ.sort()
console.log(univ);

/* Request 2: Create a new array called contactInfo that contains both first name and email of each student.

The resulting contact information should have a space between the first name and the email information like this:
Name email@example.com

Log the result of your new array. */
const contactInfo = [];
console.log(contactInfo);

const contactInfo = []; //*
for (let i = 0; i < graduates.length; i++) {
contactInfo.push(graduates[i].first_name, graduates[i].email)
};

console.log(contactInfo); //*


/* Request 3: Find out how many universities have the string "Uni" included in their name. Create a new array called uni that contains them all. Log the result. */
const uni = [];
console.log(uni);

const univOnly = [];

for(let i = 0; i<graduates.length; i++){
if (graduates[i].university.includes("Uni") === true) {
univOnly.push(graduates[i].university);
}
}
console.log(univOnly);


// ==== ADVANCED Array Methods ====
Expand All @@ -85,35 +128,52 @@ zooAnimals = [{"animal_name":"Jackal, asiatic","population":5,"scientific_name":

/* Request 1: .forEach()

The zoo wants to display both the scientific name and the animal name in front of the habitats. Return an array with only the animal and scientific names in it. The individual values in the array should look like this "Name: Jackal, asiatic, Scientific: Canis aureus."
The zoo wants to display both the scientific name and the animal name in front of the habitats. Return an array with only the animal and scientific names in it. The individual values in the array should look like this "Name: Jackal, asiatic, Scientific: Canis aureus."

*/
const animalNames = [];

zooAnimals.forEach(function(animal) {
animalNames.push(`Name: ${animal.animal_name}, Scientific Name: ${animal.scientific_name}`)
});

console.log(animalNames);

/* Request 2: .map()

The zoos need a list of all their animal's names (names only, not scientific) converted to lower case. Create a new array named lowerCase and map over each name to convert them all to lower case. Log the resut.

*/
let lowerCaseNames = [];
lowerCaseNames = zooAnimals.map(function(animal) {
return animal.animal_name.toLowerCase();
});

const lowerCase = [];
console.log(lowerCase);

console.log(lowerCaseNames);
/* Request 3: .filter()

The zoos are concenred about animals with a lower population count. Find out which animals have a population less than 5.

*/
const largerPopulation = [];
console.log(largerPopulation);
let lowPopulation = [];

lowPopulation = zooAnimals.filter(function(animal){
return animal.population < 5;
});

console.log(lowPopulation);

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

*/
const populationTotal = 0;
let populationTotal = 0;

populationTotal = zooAnimals.reduce(function(accumulater, animal){
return accumulater + animal.population;
}, 0);

console.log(populationTotal);


Expand Down
31 changes: 29 additions & 2 deletions challenges/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,34 @@
*/

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

function CuboidMaker(attr) {
this.length = attr.length;
this.width = attr.width;
this.height = attr.height
}
CuboidMaker.prototype.volume = function(){
return `${this.length * this.width * this.height}`;
}
CuboidMaker.prototype.surfaceArea = function(){
const lw = this.length*this.width;
const lh = this.length*this.height;
const wh = this.width*this.height;
const area = lw + lh + wh
return area*2;
// this seems like a clunky solution, id like to have found a cleaner way to do this
}

const cuboid = new CuboidMaker({
length: 4,
width: 5,
height: 5
});

console.log(cuboid.volume()); // 100
console.log(cuboid.surfaceArea()); //130