Menu
Coddy logo textTech

Setup: Shape Class & Export

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

challenge icon

Challenge

In this project, we'll build a simple shape rendering system that demonstrates key Object-Oriented Programming concepts. We'll create different shapes that can describe themselves, practice inheritance, and organize our code using modules.

Your task:

  1. In `Shape.js`, create a `Shape` class with:
    • A constructor that takes one parameter: color
    • A method called describe() that returns: "A ${color} shape"
  2. Export the class using export
  3. In main.js, import the class using: import { Shape } from './Shape.js';

Try it yourself

// TODO: Import the Shape class from './Shape.js';


// Test the Shape class
const myShape = new Shape('blue');
console.log(myShape.describe()); // Outputs: "A blue shape"

All lessons in Object Oriented Programming