diff --git a/geom.js b/geom.js index d942747..fcb7055 100644 --- a/geom.js +++ b/geom.js @@ -3,6 +3,21 @@ class Rectangle { this.length = length; this.width = width; } + + isSquare(){ + if(this.length === this.width ){ + return true; + } + } + + calculateArea(){ + let area = this.length*this.width; + return area; + } + calculatePerimeter(){ + let perimeter = 2*(this.length+this.width); + return perimeter; + } } @@ -12,6 +27,39 @@ class Triangle { this.sideB = sideB; this.sideC = sideC; } + +// Equilateral Triangle: +// All three sides have equal length +// All three angles are equal to 60 degrees + isEquilateral() { + if(this.sideA === this.sideB && this.sideB === this.sideC){ + return true; + } + } + //has two equal sides + isIsosceles(){ + if(this.sideA === this.sideB) { + return true; + } + } + + //Heron's Formula + // I used Math.sqrt() to find the square root + area(){ + let s = (this.sideA + this.sideB + this.sideB)/2 + let area = s*(s-this.sideA)*(s-this.sideB)*(s-this.sideC); + return Math.sqrt(area); + } + + isObtuse(){ + let a = Math.pow(this.sideA,2); + let b = Math.pow(this.sideB,2); + let c = Math.pow(this.sideC,2); + if(c > a+b ){ + return true; + } + } + } @@ -22,6 +70,15 @@ class LineSegment { this.x2 = x2; this.y2 = y2; } + + calculateLength(){ + x1 = this.x1; + x2 = this.x2; + x3 = this.x3; + x4 = this.x4; + let length = Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2)); + return length; + } } // NOTE: DO NOT REMOVE OR ALTER