So i created two classes named Shape and Square. Square is inherting Shape .Now the problem is the task asks me to " set up the constructor so that the name
property of Square
object instances is automatically set to square
, and the sides
property is automatically set to 4
. When invoking the constructor, you should therefore just need to provide the sideLength
property."
how do i do this ? i tried to directly pass the values like constructor(‘square’,sides,4) it didnt work .
i tried the below approach aswell and it says SyntaxError: Unexpected token ‘this’.
Please help me solve this task ! Much Thanks !
class Shape{
constructor(name,sides,sideLength){
this.name = name;
this.sides = sides;
this.sideLength = sideLength;
}
calcPerimeter(){
let result=this.sides * this.sideLength;
console.log(result);
};
}
class Square extends Shape{
constructor(this.name,sides,Square.this.sideLength){
super(square,sides,4);
}
this.name=‘square’;
this.sideLength=‘sideLength’;
calcArea(){
console.log(Math.sqrt(this.sideLength));
}
}
let square= new Square(4);
square.calcArea();