# OOJS 3 - example

**URL:** <https://discourse.mozilla.org/t/oojs-3-example/58717>\
**Category:** Learn\
**Tags:** participation, learning, feedback\
**Created:** [April 26, 2020, 6:39am UTC](https://discourse.mozilla.org/t/oojs-3-example/58717 "2020-04-26T06:39:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ranjanrnj44](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/ranjanrnj44/32/32875_2.png) [@ranjanrnj44](https://discourse.mozilla.org/u/ranjanrnj44)\
**Post date:** [April 26, 2020, 6:39am UTC](https://discourse.mozilla.org/t/oojs-3-example/58717/1 "2020-04-26T06:39:35Z")

</div>

This morning I was working on object, example problem OOJS-3. Hope I did, help me to improve on it sir @chrisdavidmills

```
 class Shape {

    constructor(name, sides, sideLength) {
        //below 3 are properties
        this.name = name;
        this.sides = sides;
        this.sideLength = sideLength;

        //method
        this.calcPerimeter = function() {
            let peri = this.sides * this.sideLength;
            console.log(peri);
        }
    };
}

//create a class(square - child)that extends from (Shape - parent)
class Square extends Shape {
    constructor(sideLength) {
            super("square", 4, sideLength);
        }

        //create a method calcArea() & calcPerimeter()
    calcArea() {
        return (this.sideLength * this.sideLength);
    }

    calcPerimeter() {
        return (this.sides * this.sideLength);
    }

}

//create a class(square - child)that extends from (Shape - parent)
class Triangle extends Shape {
    constructor(sideLength) {
            super("Triangle", 3, sideLength);
        }

        //create method calcArea() & calcPerimeter()
    calcArea() {
        return (this.sideLength * this.sideLength);
    }
    calcPerimeter() {
        return (this.sides * this.sideLength);
    }

}

//pass only sides - SQUARE

let square = new Square(5);
console.log(square.name);
console.log(square.sides);
console.log(square.calcArea());
console.log(square.calcPerimeter());

//pass only sides - TRIANGLE

let triangle = new Triangle(3);
console.log(triangle.name);
console.log(triangle.sides);
console.log(triangle.calcArea());
console.log(triangle.calcPerimeter());
```

---

<div class="post-metadata">

**Author:** ![chrisdavidmills](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/chrisdavidmills/32/21688_2.png) [@chrisdavidmills](https://discourse.mozilla.org/u/chrisdavidmills)\
**Post date:** [April 27, 2020, 9:06am UTC](https://discourse.mozilla.org/t/oojs-3-example/58717/2 "2020-04-27T09:06:28Z")

</div>

Well hi there @ranjanrnj44! I’ve had a look over your code and it looks like it works pretty much fine. You can [see what we did here](https://github.com/mdn/learning-area/blob/master/javascript/oojs/tasks/oojs/marking.md#task-3)

The only thing I’d say is that the area of an equalateral triangle is not just sideLength \* sideLength. You’d have to plug in the correct formula here.

---

<div class="post-metadata">

**Author:** ![ranjanrnj44](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/ranjanrnj44/32/32875_2.png) [@ranjanrnj44](https://discourse.mozilla.org/u/ranjanrnj44)\
**Post date:** [April 27, 2020, 9:14am UTC](https://discourse.mozilla.org/t/oojs-3-example/58717/3 "2020-04-27T09:14:02Z")

</div>

😬 I missed the formulae. And I really thank you Sir, I’ve been following your comments that you’ve made and tips you give to all friends here, It’s really helpful & improves my coding skills.
