-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeTimeInWords.js
50 lines (48 loc) · 1.48 KB
/
theTimeInWords.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
/*
* Complete the 'timeInWords' function below.
*
* The function is expected to return a STRING.
* The function accepts following parameters:
* 1. INTEGER h
* 2. INTEGER m
*/
function timeInWords(h, m) {
// Write your code here
let tab = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
"eleven", "twelve", "thirteen", "fourteen", "quarter", "sixteen", "seventeen", "eighteen",
"nineteen", "twenty", "twenty one", "twenty two", "twenty three", "twenty four", "twenty five",
"twenty six", "twenty seven", "twenty eight", "twenty nine"];
let mn = '';
let heures = '';
let diff = 0;
if(m == 0){
mn = "o' clock";
heures = tab[h];
return heures + " " + mn;
}else if(m>=1 && m<30){
mn = tab[m];
heures = tab[h];
if(m == 1){
return mn + " " + "minute" + " past " + heures;
}else if(m == 15){
return mn + " past " + heures;
}else{
return mn + " minutes " + "past " + heures;
}
}else if(m == 30){
heures = tab[h];
return "half past " + heures;
}else if(m>30 && m<60){
heures = tab[h+1];
if(m == 45){
return "quarter to" + " " + heures;
}else{
diff = 60 - m;
mn = tab[diff];
return mn + " " + "minutes to" + " " + heures;
}
}
}
let h= 3;
let m = 30;
console.log(timeInWords(h, m));