Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function numbersWords([arg1]){
  2.     let num = Number(arg1);
  3.    
  4.     let firstDigit = Math.trunc(num / 10);
  5.     let secondDigit = num % 10;
  6.  
  7.     if (num === 0){
  8.         console.log("zero");
  9.     } else if (num === 1){
  10.         console.log("one");
  11.     } else if (num === 2){
  12.         console.log("two");
  13.     } else if (num === 3){
  14.         console.log("three");
  15.     } else if (num === 4){
  16.         console.log("four");
  17.     } else if (num === 5){
  18.         console.log("five");
  19.     } else if (num === 6){
  20.         console.log("six");
  21.     } else if (num === 7){
  22.         console.log("seven");
  23.     } else if (num === 8){
  24.         console.log("eight");
  25.     } else if (num === 9){
  26.         console.log("nine");
  27.     } else if (num === 10){
  28.         console.log("ten");
  29.     } else if (num === 11){
  30.         console.log("eleven");
  31.     } else if (num === 12){
  32.         console.log("twelve");
  33.     } else if (num === 13){
  34.         console.log("thirteen");
  35.     } else if (num === 14){
  36.         console.log("fourteen");
  37.     } else if (num === 15){
  38.         console.log("fifteen");
  39.     } else if (num === 16){
  40.         console.log("sixteen");
  41.     } else if (num === 17){
  42.         console.log("seventeen");
  43.     } else if (num === 18){
  44.         console.log("eighteen");
  45.     } else if (num === 19){
  46.         console.log("nineteen");
  47.     }
  48.  
  49.     if (firstDigit === 2){
  50.         firstDigit = "twenty";
  51.     } else if (firstDigit === 3){
  52.         firstDigit = "thirty";
  53.     } else if (firstDigit === 4){
  54.         firstDigit = "forty";
  55.     } else if (firstDigit === 5){
  56.         firstDigit = "fifty";
  57.     } else if (firstDigit === 6){
  58.         firstDigit = "sixty";
  59.     } else if (firstDigit === 7){
  60.         firstDigit = "seventy";
  61.     } else if (firstDigit === 8){
  62.         firstDigit = "eighty";
  63.     } else if (firstDigit === 9){
  64.         firstDigit = "ninety";
  65.     }
  66.  
  67.     if (secondDigit === 1){
  68.         secondDigit = "one";
  69.     } else if (secondDigit === 2){
  70.         secondDigit = "two";
  71.     } else if (secondDigit === 3){
  72.         secondDigit = "three";
  73.     } else if (secondDigit === 4){
  74.         secondDigit = "four";
  75.     } else if (secondDigit === 5){
  76.         secondDigit = "five";
  77.     } else if (secondDigit === 6){
  78.         secondDigit = "six";
  79.     } else if (secondDigit === 7){
  80.         secondDigit = "seven";
  81.     } else if (secondDigit === 8){
  82.         secondDigit = "eight";
  83.     } else if (secondDigit === 9){
  84.         secondDigit = "nine";
  85.     }
  86.    
  87.     if (num > 20 && num < 100 && secondDigit !== 0){
  88.         console.log(firstDigit + " " + secondDigit);
  89.     }
  90.  
  91.     if(secondDigit === 0 && num !== 100 && firstDigit !== 0 && firstDigit !== 1){
  92.         console.log(firstDigit);
  93.     }
  94.  
  95.     if(num === 100){
  96.         console.log("one hundred");
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement