Advertisement
3vo

Problem 3. Check for a Play Card

3vo
Oct 25th, 2022
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.77 KB | Source Code | 0 0
  1. // Classical play cards use the following signs to designate the card face: 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K and A.
  2. // Write a program that enters a string and prints β€œyes” if it is a valid card sign or β€œno” otherwise.
  3. //
  4. //Examples:
  5. //character     Valid card sign?
  6. // 5            yes
  7. // 1            no
  8. // Q            yes
  9. // q            no
  10. // P            no
  11. // 10           yes
  12. // 500          no
  13.  
  14. let input = ['500'];
  15. let print = this.print || console.log;
  16. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  17. //Get the character
  18. let char = gets();
  19.  
  20. if(char >= 2 && char <= 10) {
  21.     console.log(`yes`);
  22. } else if(char === 'J' || char === 'Q' ||char === 'K' ||char === 'A'){
  23.     console.log(`yes`);
  24. } else {
  25.     console.log('no');
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement