Skip to content

Latest commit

 

History

History

20. Instanceof operators

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

instanceof Operator

Define a class called AreaCalculator. Inside it, create a static method that let you calculate the area of the geometric figure passed as parameter. The method will let you calculate the square, the rectangle and the circle area.

class Square { constructor(side) { this.side = side; } }

class Rectangle { constructor(width, height) { this.width = width; this.height = height; } }

class Circle { constructor(radius) { this.radius = radius; } }

class AreaCalculator { // ... }

const square = new Square(4); const rectangle = new Rectangle(4, 2); const circle = new Circle(5);

console.log(AreaCalculator.calculate(square)); console.log(AreaCalculator.calculate(rectangle)); console.log(AreaCalculator.calculate(circle));