javascript class
Can I somehow shorten this code? var result = document.getElementById("result"); function Circle(pi, r) { this.pi = pi; this.r = r; this.print1 = function() { } } function Triangle(a, b, c, h) { this.a = a; this.b = b; this.c = c; this.h = h; } function Rectangle(x, y) { this.x = x; this.y = y; } Circle.prototype.calcArea = function() { result.innerHTML += "Pole tego koła wynosi: " + this.pi * this.r * this.r + "cm2" + "<br>"; } Circle.prototype.calcCircuit = function() { result.innerHTML += "Obwód tego koła wynosi: " + 2 * this.pi * this.r + "<hr>"; } Triangle.prototype.calcArea = function() { result.innerHTML += "Pole tego trójkata wynosi: " + this.a * this.h / 2 + "cm2" + "<br>"; } Triangle.prototype.calcCircuit = function() { result.innerHTML += "Obwód tego trójkąta wynosi: " + (this.a + this.b + this.c) + "<hr>"; } Rectangle.prototype.calcArea = function() { result.innerHTML += "Pole tego prostokąta wynosi: " + this.x * this.y + "cm2" + "<br>"; } Rectangle.prototype.calcCircuit = function() { result.innerHTML += "Obwód tego prostokąta wynosi: " + 2 * (this.x + this.y) + "<hr>"; } var circle = new Circle(3.14, 5); var triangle = new Triangle(3, 4, 5, 6); var rectangle = new Rectangle(6, 7); circle.calcArea(); circle.calcCircuit(); triangle.calcArea(