Skip to content
Open
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
103 changes: 64 additions & 39 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function myFunction() {
//myFunction();

//🚀🚀🚀 ⬇️ 📝 Explanation ⬇️ 📝 🚀🚀🚀:

// "internal" is a variable declared inside the function "myFunction()" making the variable a function scope. The variable "internal" can be access by any method as long as it
// is within the "myFunction()" function.



Expand All @@ -30,9 +31,12 @@ function myFunction() {
💡 NOTE: you may use a for loop for this function if you wish
*/

function summation(/*Your Code Here*/) {
/*Your Code Here*/

function summation(arg) {
let total = 0;
for(let i = 1; i <= arg; i++){
total += i;
}
return total;
}


Expand Down Expand Up @@ -60,8 +64,12 @@ const zooAnimals = [
💡 NOTE: the array returned should be an array of strings, and each string should follow this pattern: "name: {name}, scientific: {scientific name}"
*/

function animalNames(/*Your Code Here*/){
/*Your Code Here*/
function animalNames(arg){
let displayNames = [];
arg.forEach(element => {
displayNames.push(`name: ${element.animal_name}, scientific: ${element.scientific_name}`)
});
return displayNames;
}


Expand All @@ -75,8 +83,10 @@ const zooAnimals = [
💡 NOTE: Do some research for other methods that can help help you
*/

function lowerCaseNames(/*Your Code Here*/){
/*Your Code Here*/
function lowerCaseNames(arg){
return arg.map((element) => {
return element.animal_name.toLowerCase();
})
}


Expand All @@ -88,8 +98,10 @@ const zooAnimals = [
3. Return this new array
*/

function lowPopulationAnimals(/*Your Code Here*/){
/*Your Code Here*/
function lowPopulationAnimals(arg){
return arg.filter((element) => {
return element.population < 5;
})
}


Expand All @@ -102,8 +114,10 @@ const zooAnimals = [
💡 NOTE: Remember the reduce method takes two arguments: a callback (which itself takes two args - the accumulator and the item), and an initial value for the count. Check MDN/W3Schools for syntax!
*/

function USApop(/*Your Code Here*/){
/*Your Code Here*/
function USApop(arg){
return arg.reduce((accumulator, currentValue) => {
return accumulator + currentValue.population;
}, 0)
}


Expand All @@ -116,8 +130,8 @@ const zooAnimals = [
💡 NOTE: The tests for 'consume' will pass if it is created correctly and also after you correctly complete the functions 'add' and 'greeting' below in Step 2.
*/

function consume(/*Your Code Here */){
/*Your Code Here */
function consume(a, b, cb){
return cb(a, b);
}


Expand All @@ -128,8 +142,8 @@ const zooAnimals = [
2. Return the sum of those numbers
*/

function add(/*Your Code Here */){
/*Your Code Here*/
function add(a, b){
return a + b;
}


Expand All @@ -138,8 +152,8 @@ function add(/*Your Code Here */){
2. Return the product of those numbers
*/

function multiply(/*Your Code Here */){
/*Your Code Here */
function multiply(a, b){
return a * b;
}


Expand All @@ -149,16 +163,16 @@ function multiply(/*Your Code Here */){
💡 NOTE: The string returned must match the format above or the test will not pass!
*/

function greeting(/*Your Code Here */){
return /*Your Code Here */
function greeting(firstName, lastName){
return `Hello ${firstName} ${lastName}, nice to meet you!`;
}


// 🦁🦁🦁 Step 3: Check your work by un-commenting the following calls to consume(): 🦁🦁🦁
// ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️ ⬇️
// console.log(consume(2, 2, add)); // 4
// console.log(consume(10, 16, multiply)); // 160
// console.log(consume("Mary", "Poppins", greeting)); // Hello Mary Poppins, nice to meet you!
console.log(consume(2, 2, add)); // 4
console.log(consume(10, 16, multiply)); // 160
console.log(consume("Mary", "Poppins", greeting)); // Hello Mary Poppins, nice to meet you!



Expand All @@ -175,54 +189,65 @@ function greeting(/*Your Code Here */){
- Instances of CuboidMaker should initialize `length`, `width` and `height` properties
*/

function CuboidMaker(/*Your Code Here */){
/*Your Code Here */
function CuboidMaker(arg){
this.length = arg.length;
this.width = arg.width;
this.height = arg.height;
}


/* 🐴🐴🐴 Step 2: Volume Method 🐴🐴🐴
Create a method called volume using CuboidMaker's prototype that returns the volume of a given cuboid's length, width, and height
💡 NOTE: Formula for cuboid volume: length * width * height
*/



CuboidMaker.prototype.volume = function() {
return this.length * this.width * this.height;
};

/* 🐴🐴🐴 Step 3: Surface Area Method 🐴🐴🐴
Create another method called surfaceArea using CuboidMaker's prototype that returns the surface area of a given cuboid's length, width, and height.
💡 NOTE: Formula for cuboid surface area: 2 * (length * width + length * height + width * height)
*/

CuboidMaker.prototype.surfaceArea = function() {
return 2 * (this.length * this.width + this.length * this.height + this.width * this.height);
};



/* 🐴🐴🐴 Step 4: Create a new object that uses CuboidMaker (not auto graded)🐴🐴🐴
Create an object called cuboid that uses the new keyword to use our CuboidMaker constructor
Add properties and values of length: 4, width: 5, and height: 5 to cuboid. */




let 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


// 🦄🦄🦄 Topic 4: Classes 🦄🦄🦄 //
//Using CuboidMakerTwo, take your prototypes from above and refactor into class syntax. Then, create an object called cuboidTwo that uses the new keyword to use our CuboidMakerTwo class.

class CuboidMakerTwo{

constructor(arg) {
this.length = arg.length;
this.width = arg.width;
this.height = arg.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 cuboidTwo = new CuboidMakerTwo({length: 4, width: 5, height: 5});



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



Expand Down