forked from VladimirIvanov93/javascript-tasks-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroman-time.js
More file actions
40 lines (37 loc) · 829 Bytes
/
roman-time.js
File metadata and controls
40 lines (37 loc) · 829 Bytes
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
var hours = Number(process.argv[2]);
var minutes = Number(process.argv[3]);
var time="";
var higherNumbers = {
1: 'X',
2: 'XX',
3: 'XXX',
4: 'XL',
5: 'L'
};
var belowNumbers = {
0: '-',
1: 'I',
2: 'II',
3: 'III',
4: 'IV',
5: 'V',
6: 'VI',
7: 'VII',
8: 'VIII',
9: 'IX'
};
if (!isInteger(hours) || !isInteger(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
console.log("Incorrect data: time isn't valid")
process.exit(1);
}
function isInteger(n) {
return (Number(n) == n && n % 1 === 0)
}
function returnRomanTime(data) {
if (data === 0){
return "-"
}
return higherNumbers[Math.floor(data / 10)]+belowNumbers[Math.floor(data % 10)];
}
time = returnRomanTime(hours)+":"+returnRomanTime(minutes);
console.log(time)