Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Add Days

Numbers, Dates & Timersmedium

Course · Section 12: Numbers, Dates, Intl and Timers · Lecture 189: Operations With Dates

Implement `addDays(iso, n)` returning the ISO date string (`YYYY-MM-DD`) that is `n` days after the given date.

Sample tests

Input: addDays("2024-01-01", 10)
Output: "2024-01-11"
Input: addDays("2024-01-31", 1)
Output: "2024-02-01"

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Manually adding milliseconds ignores month lengths and leap years.
Approach & explanation (try first)

setUTCDate adjusts the date and rolls over months and leap years; slicing the ISO string returns the date.

Loading...
⌘/Ctrl + Enter

Run your code to see results.