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
76 changes: 72 additions & 4 deletions challenges/classes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,75 @@
// 1. Copy and paste your prototype in here and refactor into class syntax.

// Test your volume and surfaceArea methods by uncommenting the logs below:
// 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() {
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 Test ***`);
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(attr) {
super(attr);

}
}

const cuboidCopy = new CubeMaker({
length: 20,
width: 10,
height: 18
})

const cuboidCopy1 = new CubeMaker({
length: 70,
width: 5,
height: 3
})

const cuboidCopy2 = new CubeMaker({
length: 100,
width: 260,
height: 6
})

const cuboidCopy3 = new CubeMaker({
length: 35,
width: 90,
height: 100
})
console.log(`***CuboidCopy Test ***`);
console.log(cuboidCopy.volume());
console.log(cuboidCopy.surfaceArea());
console.log(`**** CuboidCopy1 Test ***`);
console.log(cuboidCopy1.volume());
console.log(cuboidCopy1.surfaceArea());
console.log(`*** CuboidCopy2 Test ***`);
console.log(cuboidCopy2.volume());
console.log(cuboidCopy2.surfaceArea());
console.log(`*** CuboidCopy3 Test ***`);
console.log(cuboidCopy3.volume());
console.log(cuboidCopy3.surfaceArea());
23 changes: 20 additions & 3 deletions challenges/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,27 @@
* Create a function named greeting that accepts a first and last name and returns "Hello first-name last-name, nice to meet you!"
*/

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

function add(add1,add2) {
return console.log(add1 + add2)
}

function multiply(num1,num2) {
return console.log(num1 * num2)
}

function greeting(firstName,lastName) {
return console.log(`Hello ${firstName} ${lastName}, 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 ====
Expand All @@ -27,6 +43,7 @@

// Explanation:

//Since internal is a variable that is inside of the nestedfunction() parent function, its available to any nested function

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

Expand Down
89 changes: 83 additions & 6 deletions challenges/objects-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,53 @@

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

const dino1 = {
name: 'tyrannosaurus',
diet: 'carnivorous',
weight: '7000kg',
length: '12m',
period: 'Late Cretaceious'

};

// stegosaurus, herbivorous, 2000kg, 9m, Late Jurassic
const dino2 = {
name: 'stegosaurus',
diet: 'herbivorous',
weight: '2000kg',
length: '9m',
period: 'Late Jurassic'

};

// velociraptor, carnivorous, 15kg, 1.8m, Late Cretaceious
const dino3 = {
name: 'velociraptor',
diet: 'carnivorous',
weight: '15kg',
length: '1.8m',
period: 'Late Cretaceious'

};

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

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

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

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

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


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


// ==== Arrays ====
Expand All @@ -50,6 +76,11 @@ const graduates = [{"id":1,"first_name":"Cynde","university":"Missouri Southern

Once you have the new array created, sort the universities alphabetically and log the result. */
const universities = [];
for(i=0;i<graduates.length; i++) {
let uni = graduates[i].university;
universities.push(uni);
universities.sort();
}
console.log(universities)

/* Request 2: Create a new array called contactInfo that contains both first name and email of each student.
Expand All @@ -59,11 +90,21 @@ Name email@example.com

Log the result of your new array. */
const contactInfo = [];
for(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 = [];
for(i=0;i<graduates.length; i++) {
let universityName = graduates[i].university;
universityName.toUpperCase;
if(universityName.includes('Uni')){
uni.push(universityName)
}
}
console.log(uni);


Expand All @@ -89,6 +130,10 @@ The zoo wants to display both the scientific name and the animal name in front o

*/
const animalNames = [];
zooAnimals.forEach(function(name) {
let newName = `Name: ${name.animal_name}, Scientific: ${name.scientific_name}.`;
animalNames.push(newName);
})
console.log(animalNames);

/* Request 2: .map()
Expand All @@ -98,6 +143,11 @@ The zoos need a list of all their animal's names (names only, not scientific) co
*/

const lowerCase = [];
zooAnimals.map(function (newName) {
let name = newName.animal_name
lowerName = name.toLowerCase();
lowerCase.push(lowerName)
});
console.log(lowerCase);

/* Request 3: .filter()
Expand All @@ -106,14 +156,21 @@ The zoos are concenred about animals with a lower population count. Find out whi

*/
const largerPopulation = [];
zooAnimals.filter(function(pop) {
if(pop.population < 5) {
largerPopulation.push(pop.animal_name);
}
})
console.log(largerPopulation);

/* 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;
const populationTotal = zooAnimals.reduce(function(total,totalPop){
return total += totalPop.population;
},0)
console.log(populationTotal);


Expand All @@ -123,3 +180,23 @@ Stretch: If you haven't already, convert your array method callbacks into arrow

*/

// zooAnimals.forEach(name => {
// let newName = `Name: ${name.animal_name}, Scientific: ${name.scientific_name}.`;
// animalNames.push(newName);
// })

// zooAnimals.map(newName => {
// let name = newName.animal_name,
// lowerName = name.toLowerCase();
// lowerCase.push(lowerName)
// });

// zooAnimals.filter(pop => {
// if(pop.population < 5) {
// largerPopulation.push(pop.animal_name);
// }
// })

// const populationTotal = zooAnimals.reduce((total,totalPop) => {
// return total += totalPop.population;
// },0)
29 changes: 24 additions & 5 deletions challenges/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
Create a constructor function named CuboidMaker that accepts properties for length, width, and height
*/


/* == Step 2: Volume Method ==
Create a method using CuboidMaker's prototype that returns the volume of a given cuboid's length, width, and height

Formula for cuboid volume: length * width * height
*/


/* == Step 3: Surface Area Method ==
Create another method using CuboidMaker's prototype that returns the surface area of a given cuboid's length, width, and height.

Formula for cuboid surface area of a cube: 2 * (length * width + length * height + width * height)
Formula
for cuboid surface area of a cube: 2 * (length * width + length * height + width * height)
*/


Expand All @@ -26,8 +25,28 @@
Add properties and values of length: 4, width: 5, and height: 5 to cuboid.
*/

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() {
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