Let a function createSquare with accepts arguments side, color which returns an object with properties same as the arguments.The values assigned to the properties should be the values assigned to the function.Other than these properties the object also has one method which return the area of square.Now create an array Box this array should contain the 3 objects which are created by calling createSquare function.And the objects should have the values[(3,black) ,(4,red) ,(5,green) ].
I have used ES5 javascript for this. The initial part I have used constructor to create the object like
function CreateBox(side, color) {
this.side = side;
this.color = color;
//function-1
areaOfSquare = function () {
let a = this.side * this.side;
console.log(a);
};
}
The Second part I am confused how to push the values of object into array.(this is how I thought of)
let box = [];
for (let i = 0; i < 3; i++) {
box[i].push(CreateBox(3, "black"));
}