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){ = name;
this.sides = sides;
this.sideLength = sideLength;

let result=this.sides * this.sideLength;


class Square extends Shape{


let square= new Square(4);



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{

console.log(this.sideLength * this.sideLength);

let square= new Square(4);

@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 napisala: