Menu
Coddy logo textTech

Circle Class Inheritance

Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 40 of 56.

challenge icon

Challenge

Your task is to create a Circle class that inherits from the Shape class.

  1. In the file called Circle.js import the Shape class at the top: import { Shape } from './Shape.js';
  2. Create a Circle class that extends Shape and export it
  3. The constructor should take two parameters: color and radius
  4. Call super(color) to initialize the parent class
  5. Store the radius as a property: this.radius = radius
  6. Import the `Circle` class in the main file

Try it yourself

import { Shape } from './Shape.js';
// TODO:  Import the `Circle` class


// 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"

All lessons in Object Oriented Programming