Recap Challenge
Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 29 of 56.
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 inheritmaterialandcolorfrom 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 inheritmaterialandcolorfrom 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
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