-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathelfdaliannumber.html
More file actions
72 lines (71 loc) · 2.51 KB
/
Copy pathelfdaliannumber.html
File metadata and controls
72 lines (71 loc) · 2.51 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
<html>
<head>
<title>Elfdalian Number Machine</title>
<style>
*{
font-family: "Verdana";
text-align: center;
}
p{
text-align: center;
font-size: 64px;
}
input{
width: 80%;
margin-left: 10%;
margin-right: 10%;
font-size: 64px;
}
</style>
</head>
<body>
<p>Elfdalian Numbers</p>
<input onkeyup="elfdalian(this.value)" placeholder="Enter a number"></input>
<p id="elf"></p>
</body>
<script>
function elfdalian(num){
console.log(num)
num = +(("" + num).replace(/ /g, "").replace(/\./g, ""))
console.log(num)
if(num == 0){
elf.textContent = ""
return 0
}
else if(isNaN(num)){
elf.textContent = "Enter a number"
return 0
}
else if(num >= 1000000){
elf.textContent = "Choose a smaller number please"
return 0
}
else if(num % 1000 == 0){
num = threedigit(Math.floor(num / 1000)) + " tusn"
}
else if(num >= 1000){
num = threedigit(Math.floor(num / 1000)) + "tusn" + threedigit(num % 1000)
}
else{
num = threedigit(num)
}
num = "" + num
num = num.replace("ttt", "tt")
num = num.replace("fyra ", "fyr ")
num = num.replace("åtta ", "ått ")
num = num.replace("niu ", "ni ")
num = num.replace("tiu ", "ti ")
console.log(num)
elf.textContent = num
}
function threedigit(n){
digits = ["", "iett", "twå", "tri", "fyra", "fem", "sjäks", "sju", "åtta", "niu", "tiu", "ellåv", "tolv", "trettą̊", "fiuortą̊", "femtą̊", "sjäkstą̊", "sjuttją̊", "åttją̊", "nittją̊"]
tens = ["", "", "tiugu", "tretti", "fyrti", "femti", "sjäksti", "sjutti", "åtti", "nitti"]
if(n < 20) return digits[n]
else if(n < 100) return tens[Math.floor(n / 10)] + digits[n % 10]
else if(n % 100 == 0) return digits[n / 100] + " undrað"
else if(n < 200) return "undrað" + threedigit(n - 100)
else return digits[Math.floor(n / 100)] + "undrað" + threedigit(n % 100)
}
</script>
</html>