chrisjaff / js_geometry

[javascript]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Geometry

NOTE: You can ignore the module is not defined error you see in the console when opening index.html in the browser. You should still be able to test your code.

Rectangle

Given the following constructor function:

class Rectangle {
  constructor(length, width) {
    this.length = length;
    this.width = width;
  }
}

Augment the class with the following methods:

  • isSquare - returns true if the rectangle is a square.
  • area - calculates the area of the rectangle.
  • perimeter - calculates the perimeter of the rectangle.

Create a few rectangles with different lengths and widths.

Bonus: Test your outcomes using Jasmine!

Triangle

Given the following constructor function:

class Triangle {
  constructor(sideA, sideB, sideC){
    this.sideA = sideA;
    this.sideB = sideB;
    this.sideC = sideC;
  }
}

Augment the class with the following methods:

Create a few rectangles with different lengths and widths.

Bonus: Test your outcomes using Jasmine!

LineSegment

Given the following constructor:

function LineSegment(x1, y1, x2, y2) {
  this.x1 = x1;
  this.y1 = y1;
  this.x2 = x2;
  this.y2 = y2;
}

Augment the class with the following method:

  • length – calculates the length of the (x1, y1) --> (x2, y2) line segment.

About

[javascript]


Languages

Language:JavaScript 95.4%Language:HTML 4.6%