Report how many days separate the two dates.
Acceptance criteria
- 1.#out should show 14.
JavaScript Tutorial · JavaScript Dates
These 10 tasks go with the JavaScript Date Arithmetic chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Dates can be compared and subtracted because they are numbers underneath.” .
1.Count the days betweenexercise · easy · 10 min
Report how many days separate the two dates.
Passes when: #out should show 14.
2.Add days to a dateexercise · easy · 10 min · practice plan
Add ten days and report the new day of the month.
Passes when: #out should show 11.
3.Compare two datesexercise · easy · 10 min · practice plan
Report whether the first date is earlier.
Passes when: #out should show earlier.
4.Test for the same momentexercise · easy · 10 min · practice plan
Compare timestamps to check two dates match.
Passes when: #out should show same moment.
5.Roll into the next monthexercise · medium · 10 min · practice plan
Add five days to January 30 and report the month number.
Passes when: #out should show 1.
6.Fix dates compared with triple equalsbug fix · easy · 8 min
Two Date objects are never identical, so compare timestamps.
Passes when: #out should show same moment.
7.Fix the wrong milliseconds per daybug fix · easy · 8 min · practice plan
A day is 1000 times 60 times 60 times 24 milliseconds.
Passes when: #out should show 14.
8.Fix the days added to the wrong partbug fix · easy · 8 min · practice plan
Adding to the month moves it far too far.
Passes when: #out should show 11.
9.Fix the subtraction reversedbug fix · easy · 8 min · practice plan
The later date must come first to give a positive gap.
Passes when: #out should show gap of 14.
10.Fix the shared date changedbug fix · easy · 8 min · practice plan
The helper changed the caller's date instead of a copy.
Passes when: #out should show 1.
Between them these tasks cover Date differences, Comparison and Adding days.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.