Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let input = ['253'];
- let print = this.print || console.log;
- let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- //get the input
- let stringInput = gets();
- //reserve empty string to fill for result
- let resultString = '';
- //in case in 3 digit string
- if (stringInput.length === 3) {
- //get the input by index and convert them to numbers in 3 digit string
- let firstDigitUnique = +stringInput[0];
- let secondDigit = +stringInput[1];
- let thirdDigit = +stringInput[2];
- //write first digit in words
- if (firstDigitUnique === 1) {
- resultString += 'one hundred '
- } else if (firstDigitUnique === 2) {
- resultString += 'two hundred ';
- } else if (firstDigitUnique === 3) {
- resultString += 'three hundred ';
- } else if (firstDigitUnique === 4) {
- resultString += 'four hundred ';
- } else if (firstDigitUnique === 5) {
- resultString += 'five hundred ';
- } else if (firstDigitUnique === 6) {
- resultString += 'six hundred ';
- } else if (firstDigitUnique === 7) {
- resultString += 'seven hundred ';
- } else if (firstDigitUnique === 8) {
- resultString += 'eight hundred ';
- } else if (firstDigitUnique === 9) {
- resultString += 'nine hundred ';
- }
- // in case if second and third index are 0
- if (secondDigit === 0 && thirdDigit === 0) {
- stringInput = '';
- } else {
- resultString += 'and';
- stringInput = secondDigit + '' + thirdDigit;
- }
- }
- //in case 2 digit string
- if (stringInput.length === 2) {
- let num = +stringInput;
- //convert input to number in unique word cases from 1 to 19
- if (num < 20) {
- if (num === 1) {
- resultString += ' one';
- } else if (num === 2) {
- resultString += ' two';
- } else if (num === 3) {
- resultString += ' three';
- } else if (num === 4) {
- resultString += ' four';
- } else if (num === 5) {
- resultString += ' five';
- } else if (num === 6) {
- resultString += ' six';
- } else if (num === 7) {
- resultString += ' seven';
- } else if (num === 8) {
- resultString += ' eight';
- } else if (num === 9) {
- resultString += ' nine';
- } else if (num === 10) {
- resultString += ' ten';
- } else if (num === 11) {
- resultString += ' eleven';
- } else if (num === 12) {
- resultString += ' twelve';
- } else if (num === 13) {
- resultString += ' thirteen';
- } else if (num === 14) {
- resultString += ' fourteen';
- } else if (num === 15) {
- resultString += ' fifteen';
- } else if (num === 16) {
- resultString += ' sixteen';
- } else if (num === 17) {
- resultString = ' seventeen';
- } else if (num === 18) {
- resultString += ' eighteen';
- } else if (num === 19) {
- resultString += ' nineteen';
- }
- } else {
- let firstDigit = +stringInput[0];
- let secondDigit = +stringInput[1];
- if (firstDigit === 2) {
- resultString += ' twenty';
- } else if (firstDigit === 3) {
- resultString += ' thirty';
- } else if (firstDigit === 4) {
- resultString += ' forty';
- } else if (firstDigit === 5) {
- resultString += ' fifty';
- } else if (firstDigit === 6) {
- resultString += ' sixty';
- } else if (firstDigit === 7) {
- resultString += ' seventy';
- } else if (firstDigit === 8) {
- resultString += ' eighty';
- } else if (firstDigit === 9) {
- resultString += ' ninety';
- }
- if (secondDigit === 0) {
- stringInput = '';
- } else {
- stringInput = '' + secondDigit;
- }
- }
- }
- //in case 1 number string
- if (stringInput.length === 1 ) {
- let num = +stringInput;
- if (num === 0) {
- resultString += 'Zero';
- } else if (num === 1) {
- resultString += ' one';
- } else if (num === 2) {
- resultString += ' two';
- } else if (num === 3) {
- resultString += ' three';
- } else if (num === 4) {
- resultString += ' four';
- } else if (num === 5) {
- resultString += ' five';
- } else if (num === 6) {
- resultString += ' six';
- } else if (num === 7) {
- resultString += ' seven';
- } else if (num === 8) {
- resultString += ' eight';
- } else if (num === 9) {
- resultString += ' nine';
- }
- }
- resultString = resultString.trim();
- let firstLetter = resultString.charAt(0).toUpperCase();
- resultString = firstLetter + resultString.substring(1);
- console.log(resultString);
Advertisement
Add Comment
Please, Sign In to add comment