0

I am working on a project where user inputs numbers in ten thousand format [10000,20000, ..., 90000] or in hundred format [100, 200,..., 900]. I have to convert the input number to word. What I have done so far is:

  1. first check the length of the string
  2. get the first two digit of the string

If the user inputs 200 then in another text box it should show two hundred, if the user input 50000 then it should show fifty thousand. .I am confused how to proceed. I have created enum for these, I do not know how to use them.

const singleDigit = {
  // for hunderd format
  "10" : "one",
  "20" : "two",
  "30" : "three",
  //...
  "90" : "nine",
}

const doubleDigit = {
  // for ten thousand format
  "10" : "ten",
  "20" : "twenty",
  "30" : "thirty",
 // ...
  "90" : "ninty",
}

function changeToWord() {
  var amount = document.getElementById("fname").value;
  let len_ = amount.length;
  let firstDigit = amount.substring(0, 2);
  console.log("length: " + len_ + "substring: " + firstDigit);
  if (len_ == 5) {
    switch (firstDigit) {

    }
  }
}
<label for="fname">Amount In Figure:</label><br>
<input type="text" id="fname" name="fname"><br>
<label for="lname">Amount In Words:</label><br>
<input type="text" id="lname" name="lname" onfocusin="changeToWord()"><br><br>
pilchard
  • 12,414
  • 5
  • 11
  • 23
user4221591
  • 2,084
  • 7
  • 34
  • 68

0 Answers0