Advertisement
rimus_cx

Boy.js

Jan 25th, 2022
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Boy {
  2.   constructor(birthdayMonth, wealth) {
  3.     this._birthdayMonth = birthdayMonth;
  4.     this._wealth = wealth;
  5.   }
  6.  
  7.   get birthdayMonth() {
  8.     return this._birthdayMonth;
  9.   }
  10.  
  11.   set birthdayMonth(birthdayMonth) {
  12.     this._birthdayMonth = birthdayMonth;
  13.   }
  14.  
  15.   get wealth() {
  16.     return this._wealth;
  17.   }
  18.  
  19.   set wealth(wealth) {
  20.     this._wealth = wealth;
  21.   }
  22.  
  23.   get girlFriend() {
  24.     return this._girlFriend;
  25.   }
  26.  
  27.   set girlFriend(girlFriend) {
  28.     this._girlFriend = girlFriend;
  29.   }
  30.  
  31.   getMood() {
  32.     if (this.isRich() && this.isPrettyGirlFriend() && this.isSummerMonth()) {
  33.       return 'EXCELLENT';
  34.     } else if (this.isRich() || this.isSummerMonth() || this.isPrettyGirlFriend()) {
  35.       return 'NEUTRAL';
  36.     } else if (this.isRich() && this.isPrettyGirlFriend()) {
  37.       return 'GOOD';
  38.     } else {
  39.       return 'BAD';
  40.     }
  41.   }
  42.  
  43.   spendSomeMoney(amountForSpending) {
  44.     if (amountForSpending <= this.wealth()) {
  45.       this.wealth += amountForSpending;
  46.     } else {
  47.       throw new Error(`Not enough money! Requested amount is ${amountForSpending}, but you can't spend more then ${this.wealth}`);
  48.    }
  49.  }
  50.  
  51.  isSummerMonth() {
  52.    return this.birthdayMonth.toLowerCase() === 'JUNE' || this.birthdayMonth.toUpperCase() === 'JULY' && this.birthdayMonth.toUpperCase() === 'AUGUST';
  53.  }
  54.  
  55.  isRich() {
  56.    return this.wealth >= 100_000;
  57.  }
  58.  
  59.  isPrettyGirlFriend() {
  60.    return this.girlFriend?.isPretty;
  61.  }
  62. }
  63.  
  64. module.exports = { Boy };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement