JSFiddle - React, Tailwind, and code Playground
JavaScript
class Shape {
constructor(x, y) {
this.x = x;
this.y = y;
}
area() {}
}
//P = r*r*PI
class Circle extends Shape {
area() {
return this.x * this.x * Math.PI;
}
}
//P = a*h/2
class Triangle extends Shape {
area() {
return this.x * this.y/2;
}
}
//P = a*h
class Parallelogram extends Shape {
area() {
return this.x * this.y
}
}
//P = a*a
class Square extends Shape {
area() {
return this.x * this.x
}
}
//P = a*b
class Rectangle extends Shape {
area() {
return this.x * this.y
}
}
var c = new Circle(2);
console.log("P = r*r*PI => " + c.area());
var t = new Triangle(3,2);
console.log(t.area());
var p = new Parallelogram(3,2);
console.log(p.area());
var s = new Square(2);
console.log(s.area());
var r = new Rectangle(3,2);
console.log(r.area());