Advertisement
kstoyanov

08. Cards

Sep 23rd, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.   const validFaces = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
  3.   const validSuits = ['♠', '♥', '♦', '♣'];
  4.   const Suits = {
  5.     SPADES: '♠',
  6.     HEARTS: '♥',
  7.     DIAMONDS: '♦',
  8.     CLUBS: '♣',
  9.   };
  10.  
  11.   class Card {
  12.     constructor(face, suit) {
  13.       if (!validFaces.includes(face)) {
  14.         throw new Error('Invalid Card Face!');
  15.       }
  16.       if (!validSuits.includes(suit)) {
  17.         throw new Error('Invalid Card Suit!');
  18.       }
  19.       this.face = face;
  20.       this.suit = suit;
  21.     }
  22.   }
  23.  
  24.   return {
  25.     Suits,
  26.     Card,
  27.   };
  28. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement