Advertisement
braveheart1989

04. Elemelons

Nov 8th, 2016
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     class Melon {
  3.         constructor(weight,melonSort) {
  4.             if (new.target === Melon) {
  5.                 throw new TypeError("Abstract class cannot be instantiated directly");
  6.             }
  7.             this._weight = weight;
  8.             this._melonSort = melonSort;
  9.             this.arrayMelon = ["Water","Fire","Earth","Air"];
  10.         }
  11.         get weight() {
  12.             return this._weight;
  13.         }
  14.         get melonSort() {
  15.             return this._melonSort;
  16.         }
  17.         toString() {
  18.             return `Sort: ${this.melonSort}\n`
  19.         }
  20.     }
  21.  
  22.     class Watermelon extends Melon {
  23.         constructor(weight,melonSort) {
  24.             super(weight,melonSort);
  25.         }
  26.         get elementIndex() {
  27.             return this.weight * this.melonSort.length;
  28.         }
  29.         toString() {
  30.             return `Element: ${this.arrayMelon[0]}\n`+ super.toString() + `Element index: ${this.elementIndex}`
  31.         }
  32.     }
  33.  
  34.     class Firemelon extends Melon{
  35.         constructor(weight,melonSort) {
  36.             super(weight,melonSort);
  37.         }
  38.         get elementIndex() {
  39.             return this.weight * this.melonSort.length;
  40.         }
  41.         toString() {
  42.             return `Element: ${this.arrayMelon[1]}\n`+ super.toString() + `Element index: ${this.elementIndex}`
  43.         }
  44.     }
  45.     class Earthmelon extends Melon{
  46.         constructor(weight,melonSort) {
  47.             super(weight,melonSort);
  48.         }
  49.         get elementIndex() {
  50.             return this.weight * this.melonSort.length;
  51.         }
  52.         toString() {
  53.             return `Element: ${this.arrayMelon[2]}\n`+ super.toString() + `Element index: ${this.elementIndex}`
  54.         }
  55.     }
  56.     class Airmelon extends Melon{
  57.         constructor(weight,melonSort) {
  58.             super(weight,melonSort);
  59.         }
  60.         get elementIndex() {
  61.             return this.weight * this.melonSort.length;
  62.         }
  63.         toString() {
  64.             return `Element: ${this.arrayMelon[2]}\n`+ super.toString() + `Element index: ${this.elementIndex}`
  65.         }
  66.     }
  67.  
  68.     class Melolemonmelon extends Watermelon {
  69.         constructor(weight,melonSort) {
  70.             super(weight,melonSort);
  71.             this.counter = 0;
  72.             this.arr = [Watermelon, Firemelon, Earthmelon,Airmelon]
  73.         }
  74.  
  75.         morph() {
  76.             this.toString = function () {
  77.                 return new this.arr[this.counter % 4](this.weight, this.melonSort).toString()
  78.             };
  79.             this.counter++;
  80.             return this;
  81.         }
  82.  
  83.         toString() {
  84.             let str = 'Water';
  85.             return `Element: ${str}\nSort: ${this.melonSort}\nElement Index: ${this.elementIndex}`
  86.         }
  87.  
  88.  
  89.     }
  90.  
  91.     return {Melon,Watermelon,Firemelon,Earthmelon,Airmelon,Melolemonmelon}
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement