Advertisement
braveheart1989

cards

Nov 12th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.     let Suits = {
  3.         CLUBS: "\u2663",
  4.         DIAMONDS: "\u2666",
  5.         HEARTS: "\u2665",
  6.         SPADES: "\u2660"
  7.     };
  8.     let faces = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"];
  9.     class Card {
  10.         constructor(face,suit) {
  11.             this._face = face;
  12.             this._suit = suit;
  13.             if(!(faces).includes(this._face)) {
  14.                 throw new Error("ни мой тъка");
  15.             }
  16.             if (!Object.keys(Suits).map(
  17.                     k => Suits[k]).includes(this._suit)) {
  18.                 throw new Error("ни мой бе тъпак");
  19.             }
  20.         }
  21.         get face() {
  22.             return this._face;
  23.         }
  24.         set face(face) {
  25.             //TODO make validation
  26.             if(!(faces).includes(face)) {
  27.                 throw new Error("не дей така");
  28.             }
  29.             return this._face = face;
  30.         }
  31.  
  32.         get suit() {
  33.             return this._suit;
  34.         }
  35.         set suit(suit) {
  36.             if (!Object.keys(Suits).map(
  37.                     k => Suits[k]).includes(suit)) {
  38.                 throw new Error("ни мой бе тъпак");
  39.             }
  40.             return this._suit=suit;
  41.         }
  42.  
  43.     }
  44.     return {Suits,Card}
  45. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement