Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function createCard(face, suit) {
- // Define valid faces and suits
- const validFaces = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
- const validSuits = ['S', 'H', 'D', 'C'];
- // Check if the provided face and suit are valid
- if (validFaces.includes(face) && validSuits.includes(suit)) {
- const card = {
- face,
- suit,
- toString() {
- // Use Unicode symbols for suits
- const suitSymbol = {
- 'S': '\u2660', // Spades
- 'H': '\u2665', // Hearts
- 'D': '\u2666', // Diamonds
- 'C': '\u2663' // Clubs
- };
- return `${this.face}${suitSymbol[this.suit]}`;
- }
- };
- return card;
- } else {
- throw new Error("Error");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement