Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a program that asks for a digit (0-9), and depending on the input,
- // shows the digit as a word (in English).
- // * Print “not a digit” in case of invalid input. * Use a switch statement.
- // Examples:
- // d result
- // 2 two
- // 1 one
- // 0 zero
- // 5 five
- //-0.1 not a digit
- // hi not a digit
- // 9 nine
- // 10 not a digit
- let input = ['9'];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- //Get the input and converted in number:
- let d = Number(gets());
- // Switch the digit to word:
- switch (d) {
- case 0 :
- console.log('zero');
- break;
- case 1 :
- console.log('One');
- break;
- case 2 :
- console.log('Two');
- break;
- case 3 :
- console.log('Three');
- break;
- case 4 :
- console.log('Four');
- break;
- case 5 :
- console.log('Five');
- break;
- case 6 :
- console.log('Six');
- break;
- case 7 :
- console.log('Seven');
- break;
- case 8 :
- console.log('Eight');
- break;
- case 9 :
- console.log('Nine');
- break;
- case 10 :
- console.log('Ten');
- break;
- case 11 :
- console.log('Eleven');
- break;
- default :
- console.log('not a digit')
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement