Assessment wanted for OOJS 1 and 2

Hello. This is my code:

OOJS 1:

class Shape {

name;
sides;
sideLength;

constructor(name, sides, sideLength) {
    this.name = name;
    this.sides = sides;
    this.sideLength = sideLength;
}
calcPerimeter() {
        console.log(this.sideLength*this.sides);
    }

}
  let square = new Shape ("squareee", 4, 5);
  let triangle = new Shape ("trianglee", 3, 3);

OOJS 2:

class Square extends Shape {

constructor(sideLength){
  super("squarebb", 4, sideLength);
}

calcArea() {
  console.log(this.name+this.sideLength*this.sideLength);
}
}
let square2 = new Square (5);

In oojs1, I saw other users’ solutions that read using:

    **Shape.prototype.**calcPerimeter = function() {
    return this.sides * this.sideLength
  }

… instead of just calcPerimeter(). Why is that?

ps: it’s a bit dificult to keep the indentation used in vs code when pasting it here with no tabs and such.

Hello @robmdnnyc

you doing great well done

they used the prototype way for the same thing you did using class
check this lesson to learn more about it

i know this task was for the class lesson but looks like they liked to use the other way

hope that help and have a nice day :slight_smile:

1 Like