0
Can anyone tell me the code to turn digits into words?
for example.. 321 = three two one
6 ответов
+ 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
+ 3
split the number sequence with .split("") and put a switch statement in a "for" loop (case 1: num = "one";break; e.t.c....)
+ 3
I believe we're saying the same...
+ 3
Do you want me to make it for you?
0
Can't i use a for loop instead ? and add this switch part in between the reverse number coding ?
0
yes i think soo but the diff is in my method we don't need the .split ("") method