Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(word) {
- switch (word){
- case 'zero':
- console.log(0);
- break;
- case 'one':
- console.log(1);
- break;
- case 'two':
- console.log(2);
- break;
- case 'three':
- console.log(3);
- break;
- case 'four':
- console.log(4);
- break;
- case 'five':
- console.log(5);
- break;
- case 'six':
- console.log(6);
- break;
- case 'seven':
- console.log(7);
- break;
- case 'eight':
- console.log(8);
- break;
- case 'nine':
- console.log(9);
- break;
- }
- }
- Решение с масив:
- function solve(word) {
- let num = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
- console.log(num.indexOf(word));
- }
- Или:
- function solve(word) {
- console.log(['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'].indexOf(word));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement