Days, hours and minutes

Turn a number of minutes into days, hours and minutes.

What to build

A program that splits one large number into three smaller ones with division and remainders.

Requirements

  • Read the total number of minutes.
  • Work out the whole days, then the whole hours left over, then the minutes left over.
  • Print them in one line, in the format shown.

Input

One line: a whole number of minutes.

Output

D days, H hours and M minutes. Always use these plural words, even for 1.

Constraints

The total is from 0 to 1000000. Hours must be below 24, and minutes below 60.

Example

Input:

1500

Output:

1 days, 1 hours and 0 minutes

Why it works

Math.floor gives how many full days fit. The remainder operator gives what those full days leave behind, and that smaller number is then shared out into hours and minutes in the same way.

Examples

Example 1 · Input
1500
Expected output
1 days, 1 hours and 0 minutes
Example 2 · Input
135
Expected output
0 days, 2 hours and 15 minutes

Hints

Hint 1

There are 1440 minutes in a day and 60 in an hour.

Hint 2

Math.floor(total / 1440) gives the whole days.

Hint 3

total % 1440 is what is left after the whole days. Divide that by 60 for the hours.

Solution

Show one correct solution (try it yourself first)
const total = Number(prompt());
const days = Math.floor(total / 1440);
const hours = Math.floor((total % 1440) / 60);
const minutes = total % 60;
console.log(`${days} days, ${hours} hours and ${minutes} minutes`);

Lesson: JavaScript and the web →