Convert days to seconds

“How many seconds?”, a White belt challenge from the CurlyScript Dojo. It uses what Grade 1: Variables: Boxes With Labels teaches, and 3 tests check your answer.

The challenge

Write secondsIn(days) that returns how many seconds there are in that many days. (A day has 24 hours, an hour has 60 minutes, and a minute has 60 seconds.)

Example
secondsIn(1)  // 86400

Try it

Write your answer below, then press Check my answer. Your code runs right here in your browser, and the tests tell you what works.

What the tests check

  • secondsIn(1) gives 86400
  • secondsIn(7) gives 604800
  • secondsIn(0) gives 0

Hints

Stuck? Open one hint at a time. Try again after each one.

Hint 1

Multiply days × 24 × 60 × 60.

Hint 2

Using constants like const HOURS_PER_DAY = 24; makes it easier to read.

A solution

There’s always more than one right way. Read it, make sure you understand it, then try writing it yourself without looking.

Show one possible solution
Solution
function secondsIn(days) {
  const HOURS = 24;
  const MINUTES = 60;
  const SECONDS = 60;
  return days * HOURS * MINUTES * SECONDS;
}

Learn what you need

This exercise uses what Grade 1: Variables: Boxes With Labels teaches. Read those notes first if any of it is new.

Practice makes it stick

CurlyScript is a free game that teaches JavaScript from zero: short lessons, an explanation after every answer, and Dojo challenges like this one.

Start learning