diff --git a/index.js b/index.js index e37f41ec7..d0d2063c7 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,7 @@ function myFunction() { //🚀🚀🚀 ⬇️ 📝 Explanation ⬇️ 📝 🚀🚀🚀: +//Because the internal const was defined within the myFunction scope. @@ -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(num) { + let sum = 0 + for(let i = 0;i displayNames.push(`name: ${element.animal_name}, scientific: ${element.scientific_name}`)) + return(displayNames) } @@ -75,8 +81,9 @@ const zooAnimals = [ 💡 NOTE: Do some research for other methods that can help help you */ - function lowerCaseNames(/*Your Code Here*/){ - /*Your Code Here*/ + function lowerCaseNames(arr){ + const lowerAnimals = arr.map(x => x.animal_name.toLowerCase()) + return(lowerAnimals) } @@ -88,8 +95,9 @@ const zooAnimals = [ 3. Return this new array */ - function lowPopulationAnimals(/*Your Code Here*/){ - /*Your Code Here*/ + function lowPopulationAnimals(arr){ + const lowPop = arr.filter(element => element.population < 5) + return lowPop } @@ -102,8 +110,8 @@ 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(arr){ + return(arr.reduce((pv,cv) => pv + cv.population,0)) } @@ -116,8 +124,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) } @@ -128,8 +136,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 } @@ -138,8 +146,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 } @@ -149,8 +157,8 @@ 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(a,b){ + return (`Hello ${a} ${b}, nice to meet you!`) } @@ -175,9 +183,11 @@ 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(dimensions){ + this.length = dimensions.length + this.width = dimensions.width + this.height = dimensions.height + } /* 🐴🐴🐴 Step 2: Volume Method 🐴🐴🐴 @@ -185,7 +195,10 @@ function CuboidMaker(/*Your Code Here */){ 💡 NOTE: Formula for cuboid volume: length * width * height */ - +CuboidMaker.prototype.volume = function() { + return this.length * this.width * this.height +} + /* 🐴🐴🐴 Step 3: Surface Area Method 🐴🐴🐴 @@ -193,14 +206,20 @@ function CuboidMaker(/*Your Code Here */){ 💡 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. */ - +const cuboid = new CuboidMaker ({ + length: 4, + width: 5, + height: 5 +}) @@ -214,7 +233,17 @@ function CuboidMaker(/*Your Code Here */){ //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(attrs) { + this.height = attrs.height + this.length = attrs.length + this.width = attrs.width + } + surfaceArea() { + return 2 * ((this.length * this.width) + (this.length * this.height) + (this.width * this.height)) + } + volume() { + return this.length * this.width * this.height + } }