Advertisement
3vo

Problem 8. Digit as Word

3vo
Oct 25th, 2022
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Write a program that asks for a digit (0-9), and depending on the input,
  2. // shows the digit as a word (in English).
  3. // * Print “not a digit” in case of invalid input. * Use a switch statement.
  4. // Examples:
  5. // d    result
  6. // 2    two
  7. // 1    one
  8. // 0    zero
  9. // 5    five
  10. //-0.1  not a digit
  11. // hi   not a digit
  12. // 9    nine
  13. // 10   not a digit
  14.  
  15. let input = ['9'];
  16. let print = this.print || console.log;
  17. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  18. //Get the input and converted in number:
  19. let d = Number(gets());
  20. // Switch the digit to word:
  21.  
  22. switch (d) {
  23.     case 0 :
  24.         console.log('zero');
  25.         break;
  26.     case 1 :
  27.         console.log('One');
  28.         break;
  29.     case 2 :
  30.         console.log('Two');
  31.         break;
  32.     case 3 :
  33.         console.log('Three');
  34.         break;
  35.     case 4 :
  36.         console.log('Four');
  37.         break;
  38.     case 5 :
  39.         console.log('Five');
  40.         break;
  41.     case 6 :
  42.         console.log('Six');
  43.         break;
  44.     case 7 :
  45.         console.log('Seven');
  46.         break;
  47.     case 8 :
  48.         console.log('Eight');
  49.         break;
  50.     case 9 :
  51.         console.log('Nine');
  52.         break;
  53.     case 10 :
  54.         console.log('Ten');
  55.         break;
  56.     case 11 :
  57.         console.log('Eleven');
  58.         break;
  59.     default :
  60.         console.log('not a digit')
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement