--- id: 5900f37f1000cf542c50fe92 challengeType: 5 title: 'Problem 19: Counting Sundays' --- ## Description
You are given the following information, but you may prefer to do some research for yourself.
## Instructions
## Tests
```yml tests: - text: countingSundays(1943, 1946) should return 6. testString: assert.strictEqual(countingSundays(1943, 1946), 6, 'countingSundays(1943, 1946) should return 6.'); - text: countingSundays(1995, 2000) should return 10. testString: assert.strictEqual(countingSundays(1995, 2000), 10, 'countingSundays(1995, 2000) should return 10.'); - text: countingSundays(1901, 2000) should return 171. testString: assert.strictEqual(countingSundays(1901, 2000), 171, 'countingSundays(1901, 2000) should return 171.'); ```
## Challenge Seed
```js function countingSundays(firstYear, lastYear) { // Good luck! return true; } countingSundays(1943, 1946); ```
## Solution
```js function countingSundays(firstYear, lastYear) { let sundays = 0; for (let year = firstYear; year <= lastYear; year++) { for (let month = 0; month <= 11; month++) { const thisDate = new Date(year, month, 1); if (thisDate.getDay() === 0) { sundays++; } } } return sundays; } ```