-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
87 lines (76 loc) · 1.88 KB
/
Copy pathscript.js
File metadata and controls
87 lines (76 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const form = document.getElementById("form")
const input = document.querySelector('input')
const main = document.getElementById("main")
form.addEventListener('submit', (e) => {
e.preventDefault()
const value = input.value
res = wordify(value)
})
function wordify(string) {
length = string.length;
res = ""
ones = {
1: "one",
2: "two",
3: "three",
4: "four",
5: "five",
6: "six",
7: "seven",
8: "eight",
9: "nine",
}
twos = {
1: "ten",
2: "twenty",
3: "thirty",
4: "fourty",
5: "fifty",
6: "sixty",
7: "seventy",
8: "eighty",
9: "ninety"
}
let i = 0;
temp = length
flag = 0
while (i < length) {
if (string[i] === '0') {
}else if (temp == 4) {
res += ones[string[i]] + " thousand ";
} else if (temp == 3) {
res += ones[string[i]] + " hundred and ";
} else if (temp == 2) {
if (string[i] === '1') {
flag = 1
} else {
res += twos[string[i]] + " ";
}
} else {
if (flag == 1) {
flag = 0
if (string[i] === '1') {
res += "eleven"
} else if (string[i] === '2') {
res += "twelve"
} else if (string[i] === '3') {
res += "thirteen";
} else if (string[i] === '5') {
res += 'fifteen';
} else {
res += ones[string[i]] + "teen"
}
} else {
res += ones[string[i]];
}
}
i++;
temp--;
}
const p = document.createElement('p');
p.innerHTML = `
${res}
`
main.appendChild(p)
return res;
}