Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //nodejs v4.2.6
  2.  
  3. 'use strict';
  4.  
  5. class Point {
  6.     constructor (x, y) {
  7.         this.x = x;
  8.         this.y = y;
  9.     }
  10.  
  11.     length (point) {
  12.         console.log(point);
  13.         return Math.sqrt (Math.pow(this.x - point.x, 2) + Math.pow(this.y - point.y, 2));
  14.     }
  15. }
  16.  
  17. class Triangle {
  18.     constructor (p1,p2,p3) {
  19.         this.p1 = p1;
  20.         this.p2 = p2;
  21.         this.p3 = p3;
  22.     }
  23.     calcPerimeter () {
  24.         let length1 = this.p1.length (this.p2);
  25.         let length2 = this.p2.length (this.p2);
  26.         let length3 = this.p1.length (this.p3);
  27.         return length1 + length2 + length3;
  28.     }
  29. }
  30.  
  31. let p1 = new Point (1,1);
  32. let p2 = new Point (2,2);
  33. let p3 = new Point (3,3);
  34. let triangle = new Triangle (p1,p2,p3);
  35. console.log(triangle.calcPerimeter());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement