-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
194 lines (157 loc) · 4.87 KB
/
index.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE HTML>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<title>RomanJs - Conversor Decimais, Romanos</title>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="icon" type="image/png" href="icon.png" />
<meta name="theme-color" content="#000">
<meta name="msapplication-navbutton-color" content="#000">
<meta name="apple-mobile-web-app-status-bar-style" content="#000">
<link href="https://fonts.googleapis.com/icon?family=Cinzel" rel="stylesheet">
<meta name="description" content="RomanJs uma exemplo em JS de como converter números decimais para romanos">
<meta name="keywords" content="HTML,JS,Roman,Number,Vanilla,CastNumberToRoman">
<meta name="author" content="Gabriel Darezzo">
<!--FACEBOOK METADATA-->
<meta property="og:locale" content="pt_br" />
<meta property="og:url" content="https://gabrieldarezzo.github.io/romanjs/" />
<meta property="og:title" content="RomanJs | Conversão de números decimal para romanos" />
<meta property="og:site_name" content="RomanJs" />
<meta property="og:description" content="RomanJs uma exemplo em JS de como converter números decimais para romanos" />
<meta property="og:image" content="https://gabrieldarezzo.github.io/romanjs/icon.png" />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content="32">
<meta property="og:image:height" content="32">
<meta property="og:type" content="website" />
<!--FIM FACEBOOK METADATA-->
<meta name="robots" content="index, follow" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style type="text/css">
input{
text-align: center;
}
input[type="text"]{
font-size:30px;
font-family: "Cinzel", Cinzel;
font-weight: bold;
color: #000 !important;
}
hr{
margin-top: 70px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<h4>RomanJs - Número Decimal, Romano</h4>
</div>
<div class="row">
<div class="input-field col s12">
<label for="decimal" class="active">Número Decimal:</label>
<input type="tel" placeholder="Informe um número decimal" id="decimal" autofocus maxlength="4">
</div>
<div class="input-field col s12">
<label for="roman" class="active">Número Romano:</label>
<input type="text" class="roman" id="roman" readonly="readonly">
</div>
</div>
<div class="row" style="display:none" id="prova-real-box">
<div class="col s12">
<a target="_new" id="prova-real" href=""></a>
</div>
</div>
<hr />
<div class="row">
<div class="col s12">
GitHub of Project:<br />
<a target="_new" href="https://github.com/gabrieldarezzo/gabrieldarezzo.github.io/tree/master/romanjs">RomanJs</a>
</div>
</div>
</div>
<script type="text/javascript">
const numberMap = {
//Unidade
0 : [
'' //0
,'I' //1
,'II' //2
,'III' //3
,'IV' //4
,'V' //5
,'VI' //6
,'VII' //7
,'VIII' //8
,'IX' //9
]
//Dezena
,1 : [
'' //10
,'X' //10
,'XX' //20
,'XXX' //30
,'XL' //40
,'L' //50
,'LX' //60
,'LXX' //70
,'LXXX' //80
,'XC' //90
]
,2 : [
''
,'C' //100
,'CC' //200
,'CCC' //300
,'CD' //400
,'D' //500
,'DC' //600
,'DCC' //700
,'DCCC' //800
,'CM' //900
]
,3 : [
''
,'M' //1000
]
};
//Obs número maximo é 1999
function romanJs(input){
input = input.replace(/[^0-9]/, "");
if(input == '') return'';
var number = parseInt(input);
if(number > 1999){
return "número maximo '1999'";
}
//Descobre se é Unidade, Dezena, Centana, Milhar
var orderNumber = Number(input).toString();
var orderLength = orderNumber.length;
var unidadeDezenaCentena = orderLength - 1;
var newOrder = '';
for(var i = unidadeDezenaCentena; i >= 0 ;i--){
newOrder = newOrder + orderNumber.charAt(i);
}
var finalCast = '';
for(var i = unidadeDezenaCentena; i >= 0 ;i--){
var auxVar = parseInt(newOrder.charAt(i));
finalCast = finalCast + numberMap[i][auxVar];
}
return finalCast;
}
//var numberToCast = 100;
//var result = romanJs(numberToCast);
document.getElementById("decimal").addEventListener('keyup', function() {
var romanNumber = romanJs(this.value);
document.getElementById("roman").value = romanNumber;
var numberCheck = this.value.replace(/[^0-9]/, "");
if(numberCheck == '') return false;
var provaReal = 'http://numeracaoromana.babuo.com/'+ numberCheck + '-em-numeros-romanos';
document.getElementById("prova-real-box").style = "display: block";
document.getElementById("prova-real").href = provaReal;
document.getElementById("prova-real").innerHTML = 'Checar:' + numberCheck;
});
</script>
</body>
</html>