Advertisement
3vo

Problem 7. Print a Deck of 52 Cards

3vo
Nov 2nd, 2022
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Problem 7. Print a Deck of 52 Cards
  2. //
  3. // Write a program that generates and prints all possible cards from a standard deck of 52 cards (without the jokers).
  4. //
  5. // The cards should be printed using the classical notation (like 5 of spades, A of hearts, 9 of clubs; and K of diamonds).
  6. // The card faces should start from 2 to A.
  7. //   Print each card face in its four possible suits: clubs, diamonds, hearts and spades.
  8. //   Use 2 nested for-loops and a switch-case statement.
  9.  
  10. //     Note: You may use the suit symbols instead of text.
  11. //
  12. //     Examples:
  13. //
  14. //     2 of spades, 2 of clubs, 2 of hearts, 2 of diamonds
  15. //
  16. //     3 of spades, 3 of clubs, 3 of hearts, 3 of diamonds
  17. //
  18. //     K of spades, K of clubs, K of hearts, K of diamonds
  19. //
  20. //     A of spades, A of clubs, A of hearts, A of diamonds
  21.  
  22.  
  23. for (let i = 2; i <= 52; i++) {
  24.     if (i <= 10) {
  25.         console.log(i + ' of \u2660, ' + i + ' of \u2663, ' + i + ' of \u2665, ' + i + ' of \u2666');
  26.     } else if (i === 11) {
  27.         console.log('J of \u2660, ' + 'J of \u2663, ' + 'J of \u2665, ' + 'J of \u2666');
  28.     } else if (i === 12) {
  29.         console.log('Q of \u2660, ' + 'Q of \u2663, ' + 'Q of \u2665, ' + 'Q of \u2666');
  30.     } else if (i === 13) {
  31.         console.log('K of \u2660, ' + 'K of \u2663, ' + 'K of \u2665, ' + 'K of \u2666');
  32.     } else if (i === 14) {
  33.         console.log('A of \u2660, ' + 'A of \u2663, ' + 'A of \u2665, ' + 'A of \u2666');
  34.     }
  35. }
  36.  
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement