Menu
Coddy logo textTech

Overriding & Area Method

Part of the Object Oriented Programming section of Coddy's JavaScript journey. Lesson 41 of 56.

challenge icon

Challenge

Improve the Circle class by overriding the describe() method and adding a new calculateArea() method.

Your task:

  1. Override the <strong>describe()</strong> method to return ${super.describe()} (Circle with radius ${this.radius}).

    Example: "A blue shape (Circle with radius 10)"

  2. 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)

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

Practice on your own: Online JavaScript compiler