-
Notifications
You must be signed in to change notification settings - Fork 0
/
17.js
81 lines (77 loc) · 1.24 KB
/
17.js
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
var numbers = [
"",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen"
];
var tens = [
"",
"ten",
"twenty",
"thirty",
"forty",
"fifty",
"sixty",
"seventy",
"eighty",
"ninety"
];
var hundred = "hundred";
var and = "and";
var thousand = "thousand";
var string = "";
for (var i = 1; i <= 1000; i++){
if (i < 20) {
string += numbers[i];
}
if (i >= 20 && i < 100) {
string += tens[Math.floor(i/10)];
string += numbers[i%10];
console.log(tens[Math.floor(i/10)], numbers[i%10]);
}
if (i >= 100 && i < 1000) {
console.log('i', i);
var t = i;
if (i % 100 < 20){
string += numbers[t%20]; //units
console.log(numbers[t%20]);
t = Math.floor(t/10);
} else {
string += numbers[t%10];
console.log(numbers[t%10]);
t = Math.floor(t/10);
string += tens[t%10];
console.log(tens[t%10]); //tens
}
t = Math.floor(t/10);
if (i%100 !== 0) {
string += and;
console.log(and);
}
string += hundred;
console.log(hundred);
string += numbers[t];
console.log(numbers[t]); //x hundred and...
}
if (i === 1000) {
string += numbers[1];
string += thousand;
}
}
console.log(string.length);