From 1e02a3536288451cd561e3c22de0190d5a06268f Mon Sep 17 00:00:00 2001 From: hessaAqeel Date: Mon, 4 Feb 2019 21:44:35 +0300 Subject: [PATCH 1/2] HW --- geom.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/geom.js b/geom.js index d942747..a9ebf70 100644 --- a/geom.js +++ b/geom.js @@ -1,29 +1,82 @@ class Rectangle { - constructor(length, width) { - this.length = length; + constructor(lenght, width) { + + this.lenght = lenght; this.width = width; + + } + isSquare() { + + return true; + } + area() { + + return this.length * this.width + } + perimeter() { + + return 2 * (this.length + this.width) + + } + } +let tri = new Rectangle(5, 10) + +tri.isSquare();// returns True +tri.area(); // supposed to return 50 but instead it returned NaN +tri.perimeter();// NaN + + + + class Triangle { - constructor(sideA, sideB, sideC){ + constructor(sideA, sideB, sideC) { this.sideA = sideA; this.sideB = sideB; this.sideC = sideC; } -} + isEquilateral() { + return true; + + } + isIsosceles() { + return true; + } + area() { + return this.sideC * this.sideA / 2 + } + isObtuse() { + return true; + } + + let tri = new Triangle(4, 2, 2) +tri.isEquilateral();// True +tri.isIsosceles(); // True +tri.area();// NaN +tri.isObtuse();// True + class LineSegment { - constructor(x1, y1, x2, y2){ + constructor(x1, y1, x2, y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; + + } + length() { + return Math.sqrt((x1 - x2) + (y2 - y1)) } } +let ls = new LineSegment(8, 9, 4, 3) + +ls.length(); // I think I'm doing something wrong here but it can't be caught + // NOTE: DO NOT REMOVE OR ALTER module.exports = { Rectangle: Rectangle, From 8f866d9c2b4eff21fa0c59989bc61d91e0241ef4 Mon Sep 17 00:00:00 2001 From: hessaAqeel Date: Mon, 4 Feb 2019 21:59:40 +0300 Subject: [PATCH 2/2] hw up --- geom.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/geom.js b/geom.js index a9ebf70..58ade23 100644 --- a/geom.js +++ b/geom.js @@ -7,7 +7,8 @@ class Rectangle { } isSquare() { - return true; + if (this.lenght === this.width) + return true; } area() { @@ -24,7 +25,7 @@ class Rectangle { let tri = new Rectangle(5, 10) -tri.isSquare();// returns True +tri.isSquare(); tri.area(); // supposed to return 50 but instead it returned NaN tri.perimeter();// NaN @@ -39,24 +40,30 @@ class Triangle { this.sideC = sideC; } isEquilateral() { - return true; + if (this.sideA === this.sideB && this.sideB === this.sideC) { + return true; + } else { return false; } } + + isIsosceles() { - return true; + if (this.sideA === this.sideB || this.sideB === this.sideC) + return true; } area() { return this.sideC * this.sideA / 2 } isObtuse() { - return true; + if (this.sideA || this.sideB || this.sideC > 90) // was not so clear + return true; } let tri = new Triangle(4, 2, 2) -tri.isEquilateral();// True -tri.isIsosceles(); // True +tri.isEquilateral(); +tri.isIsosceles(); tri.area();// NaN -tri.isObtuse();// True +tri.isObtuse();// @@ -69,7 +76,7 @@ class LineSegment { } length() { - return Math.sqrt((x1 - x2) + (y2 - y1)) + return Math.sqrt((x1 - x2) + (y2 - y1)) // I tried googling but it did not work ;( } }