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.)
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.
It prints
What the tests check
secondsIn(1)gives86400secondsIn(7)gives604800secondsIn(0)gives0
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
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.