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.