-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6ac280
commit af34b6f
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// You are given an integer representing the number of minutes that have elapsed since midnight. You should return a string representing the current time, in traditional spoken convention. Use numerals, except specifically the following words - midnight, noon, past, til, half, quarter. Examples: if given 30, return "half past midnight". If given 710, return "10 til noon". If given 1000, return "20 til 5 pm". | ||
|
||
function timeToEnglish(num){ | ||
if(num % 60 == 0 && (num / 60) < 12) { | ||
var currentHour = num / 60; | ||
return "It is " + currentHour + " am"; | ||
} | ||
else if(num % 60 == 0 && (num / 60) > 12) { | ||
var currentHour = num / 60; | ||
var currentHour = currentHour % 12; | ||
return "It is " + currentHour + " pm"; | ||
} | ||
else if(num % 60 == 30 && (num / 60) < 12){ | ||
var currentHour = num / 60; | ||
if(Math.floor(currentHour) == 0){ | ||
return "It is half past midnight"; | ||
} | ||
else{ | ||
return "It is half past " + Math.floor(currentHour) + " am"; | ||
} | ||
} | ||
else if(num % 60 < 30 && num % 60 != 25 && (num / 60) < 12) { | ||
var currentHour = num / 60; | ||
var currentMinute = num % 60; | ||
if(Math.floor(currentHour) == 0){ | ||
return "It is " + num + " past midnight"; | ||
} | ||
else{ | ||
return "It is " + currentMinute + " past " + Math.floor(currentHour) + " am"; | ||
} | ||
|
||
} | ||
else if(num % 60 == 25 && (num / 60) < 12) { | ||
var currentHour = num / 60; | ||
var currentMinute = num % 60; | ||
if(Math.floor(currentHour) == 0){ | ||
return "It is a quarter past midnight"; | ||
} | ||
else{ | ||
return "It is a quarter past " + Math.floor(currentHour) + " am"; | ||
} | ||
|
||
} | ||
else if(num % 60 == 45 && (num / 60) < 12) { | ||
var currentHour = num / 60; | ||
var currentMinute = num % 60; | ||
return "It is a quarter til " + Math.ceil(currentHour) + " am" | ||
} | ||
else if(num % 60 != 45 && num % 60 > 30 && (num / 60) < 12) { | ||
var currentHour = num / 60; | ||
var currentMinute = num % 60; | ||
var remainingMinute = 60 - currentMinute; | ||
return "It is " + remainingMinute + " til " + Math.ceil(currentHour) + " am" | ||
} | ||
} | ||
|
||
|
||
console.log(timeToEnglish(105)); |