Advertisement
kstoyanov

08. Cards v2

Sep 23rd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(){
  2.     let validFaces = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
  3.     let validSuits = ['♠', '♥', '♦', '♣'];
  4.     let Suits = {
  5.         SPADES: '♠',
  6.         HEARTS: '♥',
  7.         DIAMONDS: '♦',
  8.         CLUBS: '♣',
  9.     };
  10.  
  11.     class Card {
  12.         constructor(face, suit) {
  13.             this.face = face;
  14.             this.suit = suit;
  15.         }
  16.  
  17.         get face() {
  18.             return this._face;
  19.         }
  20.  
  21.         set face(face) {
  22.             if (!validFaces.includes(face)) {
  23.                 throw new Error('Invalid Card Face!');
  24.             }
  25.             this._face = face;
  26.             return;
  27.         }
  28.  
  29.         get suit() {
  30.             return this._suit;
  31.         }
  32.  
  33.         set suit(suit) {
  34.             if (!validSuits.includes(suit)) {
  35.                 throw new Error('Invalid Card Suit!');
  36.             }
  37.             this._suit = suit;
  38.             return;
  39.         }
  40.     }
  41.  
  42.     return {
  43.         Suits: Suits,
  44.         Card: Card
  45.     }
  46. }())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement