hello everyone, I need help please. the calcArea() function returns A NAN
I’ve solved it myself. Thank me? i guess.
turns out i had a variable naming problem.
heres the solution i came up with:
class Shape {
constructor(name, sides, sideLength) {
this.name = name; this.sides = sides; this.sideLength = sideLength
}
}
class Square extends Shape {
constructor(sideLength) {
super('square', 4);
this.sideLength = sideLength;
}
calcArea () {
return Math.pow(this.sideLength, 2);
}
calcPerimeter() {
return this.sides * this.sideLength;
}
}
const square = new Square(5)
console.log(square.calcArea());
// console.log(square.sideLength);
console.log(square.calcPerimeter());
//console.log(square.name)
lool sure thanks for you
but little note the class shape should not have field called sidelength the sidelenth should only be in the square shape
so remove it from the constructor of shape class
inheritance mean the subclass (square in this example)has everything the superclass(shape )
well done and have a nice day
2 Likes
Thank you very much, I will do just that.
1 Like
you very welcome