Assessment OOP for beginners test your skills

I am stuck - I have been working on this for hours and I am DONE. This is from the section called test Your Skills-OO JS for beginners - speciffically the 3rd and last exercise.

its running fine except instead of printing out the result of the calcArea function it actually prints out the actual code text instead. At first I thought maybe I had a syntax error, then I thought on the line (ref **) I was declaring an object instance of the class Shape versus creating a “child” class under the “parent” class of Shape, lastly perhaps I am overthinking this.
Here is a copy of my code:

class Shape {
constructor(name, sides, sideLength) {
this.name = name;
this.sides = sides;
this.sideLength = sideLength;
}
calcPerimeter(){
return((this.sides*this.sideLength) + ’ units’);
}
}

//create a new child mySquare class from parent Shape class
let mySquare = new Shape(‘square’, 4, 6);

//add a method to the mySquare class called calcArea area of a

square=sides**2 sq units

mySquare.calcArea = function(){
return ((this.sides**2)+’ sq units’);
}

alert (`Shape is: ${mySquare.name} and it has ${mySquare.sides}sides,

each are of length ${mySquare.sideLength} with an area of

${mySquare.calcArea}`);

//${mySquare.calcPerimeter} perimeter.

Hello @kidatheart25

you just missed a little thing that you did not created any class that called square that inhirt from shap

check this one and how the teacher class created which is subclass of person class

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance

hope that help and have a nice day :slight_smile:

instead of square I called it mySquare. The link you provided just sent me to another MDN lesson for which is ahead of the test for this module. It would be helpful to see the solution.

Actually I just recieved clarification that JS doesnt use the class function like other OO languages such as python. Therefore I rewrote the below code - its cleaner but still does the same thing as the other code in that instead of actually calculating the area it writes out the entire calcarea function instead.

class Shape {
constructor(name, sides, sideLength) {
this.name = name;
this.sides = sides;
this.sideLength = sideLength;
}
calcPerimeter(){
return((this.sides*this.sideLength) + ’ units’);
}
}

//create a new child class (Square) from parent class type Shape

class Square extends Shape{
constructor(name, sides, sidelength){

//this pulls in the values from the parent class and allows this

child class to use the word this

   super(name, sides, sidelength);
   this.name = 'square';
   this.sides = 4;
                 
}
calcArea (){
   return ((this.sides**2) +' sq units'); 
}

}

// create an instance/object of type Square called mySquare with a

sidelength of 6

let mySquare=new Square(6);

alert (`Shape is: ${mySquare.name} and it has ${mySquare.sides}

sides, each are of length ${mySquare.sideLength} with a perimeter of

${mySquare.calcPerimeter} and an area of ${mySquare.calcArea}.`);

the test for that https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Test_your_skills:_Object-oriented_JavaScript

require 3 topics

The aim of this skill test is to assess whether you've understood our Object-oriented JavaScript for beginners, Object prototypes, and Inheritance in JavaScript articles.