← Back to challenges

First Tuesday of the Month

JavaScriptHarddatesmathnumbers

Instructions

Every month, Microny™️ (a big entertainment corporation) publishes a few free videogames on their web store. You are working on a script that will notify you whenever the new games are available for download. There is not a fixed date for the new releases, but you know that it happens every first Tuesday of every month.

Write a function that, given a year and a month, returns a string with the date of when the new games will be available.

Examples

firstTuesdayOfTheMonth(1997, 1) ➞ "1997-01-07"

firstTuesdayOfTheMonth(2021, 2) ➞ "2021-02-02"

firstTuesdayOfTheMonth(2020, 3) ➞ "2020-03-03"

Notes

Months are given as numbers starting at 1 = January.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.