Search⌘ K

Exercise: Modeling Classes

Explore JavaScript object-oriented programming by creating Shape and Rectangle classes that demonstrate inheritance and data encapsulation. This lesson guides you to implement constructors with protected properties and methods to get shape names, calculate area, and check for square dimensions, strengthening your OOP skills.

Task

An architect is designing a 3D model for a new building. Given the many shapes that make up a building, he wants to calculate the area of his custom shapes. For now, he wants you to create a class or constructor function called Rectangle which can both calculate the area of his walls and also tell if a wall is squarish. Because there are lots of shapes, you will also be creating a class or constructor function for all ...