Menu
Coddy logo textTech

Recap Challenge

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

challenge icon

Challenge

Create Furniture Classes Using Inheritance

Task 1: Create a Chair Class
Create a Chair class that extends Furniture:

  • Use super() in the constructor to inherit material and color from the parent class
  • Add property: numberOfLegs
  • Add method: sit() that returns "Sitting on the chair"

Task 2: Create a Table Class
Create a Table class that extends Furniture:

  • Use super() in the constructor to inherit material and color from the parent class
  • Add property: shape
  • Add method: placeItem() that returns "Item placed on table"

Try it yourself

import { Furniture } from './furniture.js';
import { Table } from './table.js';
import { Chair } from './chair.js';


// Test code - don't modify
const myChair = new Chair("wood", "brown", 4);
console.log(myChair.describe());   // Should output "brown wood furniture"
console.log(myChair.numberOfLegs); // Should output 4
console.log(myChair.sit());        // Should output "Sitting on the chair"

const myTable = new Table("glass", "clear", "round");
console.log(myTable.describe());   // Should output "clear glass furniture"
console.log(myTable.shape);        // Should output "round"
console.log(myTable.placeItem());  // Should output "Item placed on table"

All lessons in Object Oriented Programming