0

So far this is my code:

function number(numm){
var ones = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];
  var result;
  var numString = num.toString();

  if (num === 0){
      console.log(ones[0]);
    return ones[0];
  }
if (num < 10) {
      result = ones[num];
      console.log(result);
    return result;
  }

  if (numString.length === 2) {
    result = ones[numString[0]] + ' ' + ones[numString[1]];
    console.log(result);
    return result;
  }

  if (numString.length == 3) {
    if (numString[1] === '0' && numString[2] === '0'){
        result = ones[numString[0]] + ' zero zero';
        console.log(result);
        return result;
    }
    else{
        result = ones[numString[0]] +  ones[numString[1]] + ' ' + ones[numString[2]];
        console.log(result);
        return result;
    }
  }
}

It prints whatever user inputs into its phonetic value, so when the user inputs 25, it should print TwoFive. However, I can't find anything about setting my node so that when the input is: node main.js 25 it should call my function and print TwoFive. Any pointers as to how to achieve this? Will this work for an array of elements? node main.js 3 25 should print Three, TwoFive

0 Answers0