Exercise: Computing time until midnight
Write a script that writes to the consoleA window used for debugging, usually not visible on the page. the number of minutes between the current time and midnight.
Checking your work
The arrows and dots in the header bar above can be used to navigate back and forth between your work on this page and a solution to the exercise on the next one.
Using hints
Click on the button below if you get stuck and want a hint (or two or three).
Note:
Hints:
Remember to use 24 hour time.
Solution to the exercise
Here is one possible solution.
Notice the following:
- The variable declarations are accompanied by explanatory comments.
- The methods
.getHours()
and.getMinutes()
are used to extract information about the current time. - The total number of minutes until midnight can be calculated by determining the number of minutes until the end of the current hour (
waitMins
) and the number of minutes from the end of the current hour to midnight (waitHours
)
Note:
Hints:
- undefined
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX