Overriding & Area Method
Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 41 of 56.
Challenge
Improve the Circle class by overriding the describe() method and adding a new calculateArea() method.
Your task:
Override the
<strong>describe()</strong>method to return${super.describe()} (Circle with radius ${this.radius}).Example: "A blue shape (Circle with radius 10)"
- Add a
<strong>calculateArea()</strong>method that:- Calculates the area using the formula:
Math.PI * this.radius * this.radius Returns the calculated area (no console.log needed)
*This is a Circle-specific method (not in the parent Shape class)
- Calculates the area using the formula:
Try it yourself
import { Shape } from './Shape.js';
import { Circle } from './Circle.js';
// Tests
const basicShape = new Shape('red');
console.log(basicShape.describe()); // "A red shape"
const myCircle = new Circle('blue', 10);
console.log(myCircle.describe()); // Should output: "A blue shape (Circle with radius 10)"
console.log(myCircle.calculateArea()); // Should output: "314.1592653589793"All lessons in Object Oriented Programming
1Objects & The this Keyword
Quick Review: ObjectsAdding Methods to ObjectsUnderstanding the this KeywordConstructor FunctionsThe new KeywordRecap Challenge7 Inheritance & The extends Key
InheritanceThe "is-a" RelationshipThe extends KeywordThe super() MethodInheriting Properties&MethodsRecap Challenge2Organizing Code
What are Modules?Exporting with exportImporting with importDefault vs. Named Exports8Organizing OOP Code
Organize Classes into Modules11Project: A Shape Renderer
Setup: Shape Class & ExportCircle Class Inheritance9Static Methods & Properties
Class-Level vs. Instance-LevelStatic PropertiesStatic Utility MethodsRecap challenge