← Back to challenges

Hours Passed

JavaScriptHardstringsdates

Instructions

Write a function that takes time t1 and time t2 and returns the numbers of hours passed between the two times.

Examples

hoursPassed("3:00 AM", "9:00 AM") ➞ "6 hours"

hoursPassed("2:00 PM", "4:00 PM") ➞ "2 hours"

hoursPassed("1:00 AM", "3:00 PM") ➞ "14 hours"

Notes

  • Time t1 will always be the starting time and t2, the ending time.
  • Return the string "No time has passed." if t1 is equal to t2.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.