Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Card {
- constructor(face,suit){
- this.face=face;
- this.suit=suit;
- }
- get face(){
- return this.face;
- }
- set face(valueFace){
- let valid=['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
- if(!valid.includes(valueFace)){
- throw new Error('Invalid card face:' +valueFace);
- }
- this.face=valueFace;
- }
- get suit(){
- return this.suit;
- }
- set suit(valueSuit){
- let validSuit=['C','D','H','S'];
- if(!validSuit.includes(valueSuit)){
- throw new Error('Invalid card suit:' +valueSuit)
- }
- this.suit=valueSuit;
- }
- toString(){
- let convertObj={
- 'C': "\u2663",
- 'D': "\u2666",
- 'H': "\u2665",
- 'S': "\u2660",
- }
- return this.face+convertObj[this.suit];
- }
- }
- let card=new Card('J','D');
- console.log(card);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement