Assessment wanted for OOJS 3 skill test

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();

[

https://www.google.com/

](https://www.google.com/)

Hi there @span.mojca!

You are really close on this. The problem lies in your Square constructor and use of super.

First of all, you don’t use this in your constructor arguments — this refers to the scope inside the object instance, so is only useful inside functions, etc., not in the arguments passed to the object.

Second, you should only need to pass the sideLength property into the constructor, as specified in the question.

Third, your super usage looks basically right, but you seem to have the exact nature of the arguments a bit confused. For example, square is a string, not an object, and the number of sides (4) should be the second argument.

And a last (small) point — your calcArea() method doesn’t look like it is using the right function.

Have another go. If you are still stuck, then I’ll pass you our solution to have a look at.

Good luck!

thank you so much sir ! you are the best , I spent 10 minutes reading your reply and understanding where i was wrong.

But it took me just few seconds to fix the code . You explained it very concisely !
Thanks again @chrisdavidmills ! :slight_smile:

class Square extends Shape{
constructor(sideLength){
super(‘square’,4,sideLength);
}

calcArea(){
console.log(this.sideLength * this.sideLength);
}
}

let square= new Square(4);
square.calcArea();

@walmart looks pretty much perfect to me, nice work!

And glad I was able to help.

ok lp,

V V pon., 30. mar. 2020 ob 03:30 je oseba Mojcam span.mojca@gmail.com napisala: