Created
October 7, 2019 15:12
-
-
Save simrandotdev/c3bb013f20c930fd512c60a9cb8e3b65 to your computer and use it in GitHub Desktop.
Shape.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Shape(){ | |
| let shape = []; | |
| //shape.totalVolume = totalVolume; | |
| /* Added the function add the shape in the 'shape' array. */ | |
| shape.addShape = function (newShape) { | |
| shape.push(newShape); | |
| } | |
| //console.log(shape2.computeConeVol(5,10)); | |
| shape.volume = function () { | |
| /* Instead of declaring a array, declaring a variable with initial value 0 */ | |
| let totalVolume = 0.0; | |
| shape.forEach(item => { | |
| /* Adding the volumes of shapes into the totalVolume variable. */ | |
| totalVolume = totalVolume + item.computeVolume(); | |
| }); | |
| return totalVolume; | |
| } | |
| return shape; | |
| } | |
| let Sphere = require ('./sphere'); | |
| let shape1 = new Sphere(8); | |
| let Cone = require ('./cone'); | |
| let shape2 = new Cone(5,10); | |
| /* Created the shape object and added objects to it */ | |
| let shapes = Shape(); | |
| shapes.addShape(shape1); | |
| shapes.addShape(shape2); | |
| /* Calling the volume function of the Shape class. */ | |
| console.log(shapes.volume()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment