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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ 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 will list each individual item in an array seperately and .map will give you all of the items in an array all together.

2. What is the difference between a function and a method?
A function is a container, it has a list of methods inside of it which can be inherit.

3. What is closure?
A closure could be labled as function, or using class. It has a bunch of methods inside of it.

4. Describe the four rules of the 'this' keyword.
- .this needs to be in refference to the object properties you are using.
- .this must be used in a constructor or else it wont instantiate.
- .this all by itself will reference the entire window
- .this binds to context

5. Why do we need super() in an extended class?
Super gives the inheritance chain access to its functions.kind of like call does.

## Project Set up

Expand Down
53 changes: 52 additions & 1 deletion challenges/classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,55 @@
// 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.

//BASECONSTRUCTOR
class CuboidMaker {
constructor(add) {
this.length = add.length;
this.width = add.width;
this.height = add.height;
}
//METHODS
volume() {
return ( this.length * this.width * this.height);
}
surfaceArea() {
return( 2 * (this.length * this.width + this.length * this.height + this.width * this.height));
}
}

class CuboidMaker2 extends CuboidMaker{
constructor(math) {
super(math)
}
//METHODS
volume() {
return ( this.length * this.width * this.height);
}
surfaceArea() {
return( 2 * (this.length * this.width + this.length * this.height + this.width * this.height));
}
}

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

const cuboid2 = new CuboidMaker2 ({
length: 4,
width: 5,
height: 5
});

console.log("The Volume of this Cuboid is:");
console.log(cuboid.volume());
console.log("The Suface Area of this Cuboid is:")
console.log(cuboid.surfaceArea());
console.log("The Volume of this Cuboid 2 is:");
console.log(cuboid2.volume());
console.log("The Suface Area of this Cuboid 2 is:")
console.log(cuboid2.surfaceArea());
22 changes: 22 additions & 0 deletions challenges/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,35 @@
// consume(10,16,multiply); // 160
// consume("Mary","Poppins", greeting); // Hello Mary Poppins, nice to meet you!

function consume(param1, param2, callbackFunction) {
return callbackFunction(param1,param2);
}

function add(a, b) {
return a + b;
}

function multiply(a, b) {
return a * b;
}

function greeting(firstName, lastName) {
return `Hello ${firstName} ${lastName}, nice to meet you!`;
}


console.log(consume(2,4,add));
console.log(consume(10,16,multiply));
console.log(consume("Marry","Poppins", greeting));


// ==== Closures ====

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

// Explanation:

//The function nested function had access to whats inside of it, it can console.log(internal) because it has access to it. internal doesnt have access to external, it doesnt work that way.

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

Expand Down
147 changes: 131 additions & 16 deletions challenges/objects-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,81 @@
object name, diet, weight, length, period
*/

class Dino {
constructor (rawr) {
this.diet = rawr.diet;
this.weight = rawr.weight;
this.length = rawr.length;
this.period = rawr.period;
this.rawr = rawr.rawr;
}
tyrannosaurusWeight() {
return `${this.weight}`;
}
stegosaurusLength() {
return `${this.length}`;
}
velociraptorDiet() {
return `${this.diet}`;
}
tyrannosaurusPeriod() {
return `${this.period}`;
}
tyrannosaurusRawr() {
return `${this.rawr}`;
}

}

const tyrannosaurus = new Dino ({
diet: 'carnivorous',
weight: '7000kg',
length: '12m',
period: 'Late Cretaceious',
rawr: 'RAWERSRARARWERSARARARRRR!'
});

const stegosaurus = new Dino ({
diet: 'herbivorous',
weight: '2000kg',
length: '9m',
period: 'Late Jurassic'
});

const velociraptor = new Dino ({
diet: 'carnivorous',
weight: '15kg',
length: '1.8m',
period: 'Late Cretaceious'
});

// stegosaurus, herbivorous, 2000kg, 9m, Late Jurassic

// velociraptor, carnivorous, 15kg, 1.8m, Late Cretaceious

// Using your dinosaur objects, log answers to these questions:

// How much did tyrannosaurus weigh?
console.log('The weight of a Tyrannosaurus:');
console.log(tyrannosaurus.tyrannosaurusWeight());

// What was the diet of a velociraptor?
console.log('The diet of a Velociraptor:');
console.log(velociraptor.velociraptorDiet());

// How long was a stegosaurus?
console.log('The Stegosaurus length is:');
console.log(stegosaurus.stegosaurusLength());

// What time period did tyrannosaurus live in?
console.log('The Tyrannosaurus lived in the time period of:');
console.log(tyrannosaurus.tyrannosaurusPeriod());


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

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

// stegosaurus, herbivorous, 2000kg, 9m, Late Jurassic
Expand All @@ -15,20 +90,20 @@
// Using your dinosaur objects, log answers to these questions:

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

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

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

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


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


// ==== Arrays ====
Expand All @@ -49,16 +124,28 @@ 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 universities = [];
console.log(universities)
for (let i = 0; i < graduates.length; i++) {
universities.push(graduates[i].university);
};
console.log(universities.sort());

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


Expand All @@ -67,6 +154,15 @@ const uni = [];
console.log(uni);


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


// ==== ADVANCED Array Methods ====

// Given this zoo data from around the United States, follow the instructions below. Use the specific array methods in the requests below to solve the problems.
Expand All @@ -88,38 +184,57 @@ zooAnimals = [{"animal_name":"Jackal, asiatic","population":5,"scientific_name":
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 = [];
console.log(animalNames);
// const animalNames = [];
// console.log(animalNames);

zooAnimals.forEach(function(names) {
console.log(names.animal_name + ' ' + names.scientific_name);
});

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

*/

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

let lower = zooAnimals.map(function(names) {
return names.animal_name.toLowerCase();
});

/* 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);
// const largerPopulation = [];
// console.log(largerPopulation);

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

});

/* 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;
console.log(populationTotal);
// const populationTotal = 0;
// console.log(populationTotal);

let add = zooAnimals.reduce(function(total, animal){
return total + animal.population;
}, 0);

console.log(add);

/*

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

*/

*/
Loading