Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions geom.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
class Rectangle {
//constructor take a length and width
constructor(length, width) {
this.length = length;
this.width = width;
}
}

// method isSquare
isSquare(){
return this.length === this.width;
}
// calculatesArea method
calculatesArea(){
return this.length*this.width;
}
//calculates the perimeter of the rectangle
calculatesPerimeter(){
return (2*this.length)+(2*this.width);
}
}// end class rectangle

// Triangle
class Triangle {
constructor(sideA, sideB, sideC){
this.sideA = sideA;
this.sideB = sideB;
this.sideC = sideC;
}
// method isEquilateral() return true if al side equal
isEquilateral(){
return this.sideA === this.sideB === this.sideC;//return
}
// true if at least tow side is equal
isIsosceles(){
return this.sideA === this.sideB || this.sideB=== this.sideC||this.sideA === this.sideC;
}
// method calculatesArea
calculatesArea(){
let s=(this.sideA+this.sideB+this.sideC)/2; // assign the semi-perimeter of the triangle
return Math.sqrt((s*(s-this.sideA))*(s-this.sideB)*(s-this.sideC));// return area
}

//check sideA^2 + sideB^2 less than sideC^2
isObtuse(){
return (Math.pow(this.sideA,2)+Math.pow(this.sideB,2)) < (Math.pow(this.sideC,2));//return true or false
}
}


Expand All @@ -22,6 +53,10 @@ class LineSegment {
this.x2 = x2;
this.y2 = y2;
}
// calculate the distance between two points
length(){
return Math.sqrt((Math.pow(this.x1-this.x2,2))+(Math.pow(this.y1-this.y2,2)));
}
}

// NOTE: DO NOT REMOVE OR ALTER
Expand Down
7 changes: 7 additions & 0 deletions spec/geometry_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ var Triangle = Geom.Triangle;
var LineSegment = Geom.LineSegment;

describe('Rectangle', function() {
//foo
// beforeEach(function(){
// foo=1
// });
// afterEach(function(){
// foo=0;
// });
it('is a class that is defined', function () {
expect(Rectangle).toBeDefined()
})
Expand Down