0

Can anyone tell me the code to turn digits into words?

for example.. 321 = three two one

27th Dec 2016, 3:44 PM
Harshit
6 Respostas
+ 4
window.onload = function(){conv(prompt("insert number"));}; function conv(txt){ var str = txt.split(""); for (var stp = 0; stp < str.length; stp++){ if (str[stp] == 1){ str[stp] = "one "; } else if (str[stp] == 2){ str[stp] = "two "; } else if (str[stp] == 3){ str[stp] = "three "; } else if (str[stp] == 4){ str[stp] = "four "; } else if (str[stp] == 5){ str[stp] = "five "; } else if (str[stp] == 6){ str[stp] = "six "; } else if (str[stp] == 7){ str[stp] = "seven "; } else if (str[stp] == 8){ str[stp] = "eight "; } else if (str[stp] == 9){ str[stp] = "nine "; } else { str[stp] = "zero "; }//if }//for document.write(str.join("")); }//func
27th Dec 2016, 4:11 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
split the number sequence with .split("") and put a switch statement in a "for" loop (case 1: num = "one";break; e.t.c....)
27th Dec 2016, 3:47 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
I believe we're saying the same...
27th Dec 2016, 3:50 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
Do you want me to make it for you?
27th Dec 2016, 3:50 PM
Valen.H. ~
Valen.H. ~ - avatar
0
Can't i use a for loop instead ? and add this switch part in between the reverse number coding ?
27th Dec 2016, 3:49 PM
Harshit
0
yes i think soo but the diff is in my method we don't need the .split ("") method
27th Dec 2016, 3:51 PM
Harshit