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

class CuboidMaker {
constructor(attr) {
this.length = attr.length;
this.width = attr.width;
this.height = attr. height;
}

//method
volume(width, length, height) {
const volume = `${this.width}` * `${this.length}` * `${this.height}`;
return `${volume}`;
}
//method
surfaceArea(width, length, height) {
const surfaceArea = 2 *(`${this.length}` * `${this.width}` + `${this.length}` * `${this.height}` + `${this.width}` * `${this.height}`);
return `${surfaceArea}`;
};
}

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
Expand Down
37 changes: 26 additions & 11 deletions challenges/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,33 @@
* In the body of the function return the callback with the two parameters that you created
*/

function consumeFood(food1, food2) {
console.log(`I like to eat ${food1}, ${food2}`);
function bake(param1, param2, callback) {
brownies(param1, param2);
}
function brownies(param1, param2) {
console.log(param1 + param2);
}

function consumeFoodThatIsSweet(callback) {
const sweetFood = 'candy';
const sweetFood2 = 'donuts';
const sweetFood3 = 'chocolate';
callback(sweetFood);
function macaroons(param1, param2) {
console.log(param1 + param2);
};


bake('eggs', 'milk', 'macaroons');


function consume(param1, param2, callback) {
console.log(param1 + param2)
}
function add(param1, param2) {
console.log(param1 + param2);
}
function multiply(param1, param2, callback) {
console.log(param1 * param2);
};

consumeFoodThatIsSweet(consumeFood);




/* Step 2: Create several functions to callback with consume();
Expand All @@ -39,8 +53,8 @@ consumeFoodThatIsSweet(consumeFood);

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

// Explanation:

// Explanation:When my myFunction is invoked the 2 pass compiler looks looks for a reference. It looks up myFunction. It knows that nestedFunction is invoked and looks for it's reference.
//It can't find a reference so it goes to the next function to find it. It grabs the reference from where it orignated because lexicolscope. Closures are awesome little backpacks that store info for later.

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

Expand All @@ -53,4 +67,5 @@ function myFunction() {
};
nestedFunction();
}
myFunction();
myFunction();

77 changes: 68 additions & 9 deletions challenges/objects-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ console.log(dinosaur1.period);

// Create a new roar method for the tyrannosaurus. When called, return "RAWERSRARARWERSARARARRRR!" Log the result.

const dinosaur1 = {
const noisyDinosaur = {
name: 'tyrannosaurus',
diet: 'carnivorous',
weight: '7000kg',
Expand Down Expand Up @@ -95,7 +95,7 @@ const universities = [



Once you have the new array created, sort the universities alphabetically and log the result. */
/*nce you have the new array created, sort the universities alphabetically and log the result. */
const universities = [
"Coastal Carolina University",
"Fachhochschule Rosenheim, Hochschule für Technik und Wirtschaft",
Expand Down Expand Up @@ -166,33 +166,92 @@ 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 = [];
const animalNames = [
{'Name': 'Jackal, asiatic', 'Scientific': 'Canis aureus',},
{'Name': 'Screamer, southern', 'Scientific': 'Chauna torquata',},
{'Name': 'White spoonbill', 'Scientific': 'Platalea leucordia',},
{'Name': 'White-cheeked pintail', 'Scientific': 'Anas bahamensis',},
{'Name': 'Black-backed jackal', 'Scientific': 'Canis mesomelas',},
{'Name': 'Brolga crane', 'Scientific': 'Grus rubicundus',},
{'Name': 'Common melba finch', 'Scientific': 'Pytilia melba',},
{'Name': 'Pampa gray fox', 'Scientific': 'Pseudalopex gymnocercus',},
{'Name': 'Hawk-eagle, crowned', 'Scientific': 'Spizaetus coronatus',},
{'Name': 'Australian pelican', 'Scientific': 'Pelecanus conspicillatus',},
];


zooAnimals.forEach(function(element1) {
console.log(element1.animal_name);
});

zooAnimals.forEach(function(element2) {
console.log(element2.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.

*/
const lowerCase = [
"jackal, asiatic",
"screamer, southern",
"white spoonbill",
"white-cheeked pintail",
"black-backed jackal",
"brolga crane",
"common melba finch",
"pampa gray fox",
"hawk-eagle", "crowned",
"australian pelican",
];


const newZooAnimals = zooAnimals.map(function callback(currentValue){
return currentValue.animal_name.toLowerCase();
});
console.log(newZooAnimals);




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

/* 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 = [
{"animal_name":"Screamer, southern","population":1,"scientific_name":"Chauna torquata","state":"Alabama"},
{"animal_name":"White-cheeked pintail","population":1,"scientific_name":"Anas bahamensis","state":"Oregon"},
{"animal_name":"Black-backed jackal","population":2,"scientific_name":"Canis mesomelas","state":"Washington"},
];


const largerPop = zooAnimals.filter(zooAnimals => zooAnimals.population < 4);
console.log(largerPop);

/* 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 = 56;

const popTotal = zooAnimals.reduce(function(population, currentValue) {
return population + currentValue.population;
}, 0);

console.log(popTotal);









/*
Expand Down
40 changes: 40 additions & 0 deletions challenges/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,48 @@
Add properties and values of length: 4, width: 5, and height: 5 to cuboid.
*/

//base constructor
function CuboidMaker(attr) {
this.length = attr.length;
this.width = attr.width;
this.height = attr. height;
}

//method
CuboidMaker.prototype.volume = function(width, length, height) {
const volume = `${this.width}` * `${this.length}` * `${this.height}`;
return `${volume}`;
}

//method
CuboidMaker.prototype.surfaceArea = function(width, length, height) {
const surfaceArea = 2 *(`${this.length}` * `${this.width}` + `${this.length}` * `${this.height}` + `${this.width}` * `${this.height}`);
return `${surfaceArea}`;
};



//Object

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

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




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