# Assessment wanted for OOJS 3

**URL:** <https://discourse.mozilla.org/t/assessment-wanted-for-oojs-3/77925>\
**Category:** Learn\
**Tags:** learning, feedback, issue\
**Created:** [March 31, 2021, 1:18am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-oojs-3/77925 "2021-03-31T01:18:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![patlo](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/patlo/32/45656_2.png) [@patlo](https://discourse.mozilla.org/u/patlo)\
**Post date:** [March 31, 2021, 1:18am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-oojs-3/77925/1 "2021-03-31T01:18:06Z")

</div>

Hi, been using this forum for help with some of the testing your skills portions of OOJS and had a question regarding ES6 inheritance syntax.

So I think I’ve got the solution here, but I was wondering why one only puts in sideLength in the Square constructor and everything else in super.

In a previous example on inheritance, when creating the new subclass of Teacher based on Person we pass in everything to Teacher and Person, do we not?  
[As shown here](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance#ecmascript_2015_classes)

```auto
class Teacher extends Person {
  constructor(first, last, age, gender, interests, subject, grade) {
    super(first, last, age, gender, interests);

    // subject and grade are specific to Teacher
    this.subject = subject;
    this.grade = grade;
  }
}

```

When I did that for OOJS 3 I got back error messages.

Why do we only need to pass one argument here as opposed to all of them in Teacher? Is there a reason for it described on that page I linked to that I’m glossing over?

I have gone through all the OOJS pages prior to this, but still having trouble understanding it if someone could help me with that.

Here is my solution to OOJS 3

```
class Shape {
    constructor(name, sides, sideLength) {
        this.name = name;
        this.sides = sides;
        this.sideLength = sideLength;
    }

    // Write your code below here

    calcPerimeter() {
        alert(`${this.sides * this.sideLength}`);
    }

}

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

    calcArea() {
        alert(this.sideLength * this.sideLength);

    }
}

let square = new Square(10);
let triangle = new Shape('triangle', 3, 3);

// Calling the functions
square.calcArea();

```

Thanks!

---

<div class="post-metadata">

**Author:** ![Ran](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/ran/32/56779_2.png) [@Ran](https://discourse.mozilla.org/u/Ran)\
**Post date:** [March 31, 2021, 7:26am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-oojs-3/77925/2 "2021-03-31T07:26:17Z")

</div>

Hi @patlo,  
This is a great question. It made me think again of this section and thanks for posting it.

The way I understand it is this.

1. When constructing a subclass the constructor statement is for the parameters for the new class we are creating.

```auto
    constructor(sideLength) {

```

In the case of the square subsclass it is based off the shape class. However the square class only needs one parameter sidelength as we already know that a square will have 4 sides and will always be named square.

1. When creating a subclass based on the extends method we have to use the super to initialise the class we are basing the new subclass on otherwise we get the [following error as stated by MDN](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance#inheritance_with_class_syntax)

```auto
Uncaught ReferenceError: Must call super constructor in derived class before
accessing 'this' or returning from derived constructor

```

As MDN states in the same section

> Unlike old-school constructor functions where the [`new` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new) does the initialization of `this` to a newly-allocated object, this isn’t automatically initialized for a class defined by the [extends](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends) keyword, i.e the sub-classes.

In the case of the square we use the super statement to initialise the shape class but we only need an open parameter of sideLenth while the name and sides are given as constants i.e. hardcoded to the super.

1. This means that when you need to create a square you only need to provide one arguement as the class only has one parameter with the other two parameters being hardcoded into the shape class.

I am a learner like you so please let me know if this makes any sense to you. It would really help me progress in the way I understand it as well.

Good luck with your studies.

---

<div class="post-metadata">

**Author:** ![ayodeji](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@ayodeji](https://discourse.mozilla.org/u/ayodeji)\
**Post date:** [October 22, 2021, 4:08am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-oojs-3/77925/3 "2021-10-22T04:08:35Z")

</div>

Also makes sense to me. Began learning earlier this month and I have the same concerns as @patlo.

You guys understand it better now?

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [October 22, 2021, 10:09am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-oojs-3/77925/4 "2021-10-22T10:09:18Z")

</div>

Hi @ayodeji and welcome to the community 👋

In my opinion, @Ran gave a correct explanation of the situation. Can you tell me which part isn’t clear? I’m happy to help you understanding it 😊

Have a nice day!  
Michael

---

<div class="post-metadata">

**Author:** ![ayodeji](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@ayodeji](https://discourse.mozilla.org/u/ayodeji)\
**Post date:** [October 26, 2021, 12:18am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-oojs-3/77925/5 "2021-10-26T00:18:18Z")

</div>

His description is astute. I come from C++ so it’s just the different ways of doing the same thing that’s bothering me I guess.

With more practice I’m sure I’ll be fine.

---

<div class="post-metadata">

**Author:** ![mikoMK](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/mikomk/32/50456_2.png) [@mikoMK](https://discourse.mozilla.org/u/mikoMK)\
**Post date:** [October 26, 2021, 1:08am UTC](https://discourse.mozilla.org/t/assessment-wanted-for-oojs-3/77925/6 "2021-10-26T01:08:04Z")

</div>

Understood.  
It can be hard coming from another language. You know the concepts but the devil is in the details as they say.
