JavaScript Date Components — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Date Components lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Read the hours
easy10 minReport the UTC hours of the date.
- 2
Read the weekday number
easy10 minReport the weekday number, where Sunday is zero.
- 3
Name the weekday
easy10 minUse an array to turn the number into a name.
- 4
Change the year
easy10 minSet the year to 2027 and report it.
- 5
Build a padded time
medium10 minShow the time with leading zeros.
Find the bug(5)
- 1
Fix getDate used for the weekday
easy8 mingetDate is the day of the month; getDay is the weekday.
- 2
Fix the unpadded time
easy8 minSingle digits need a leading zero.
- 3
Fix the year set with the wrong method
easy8 minsetUTCMonth changes the month, not the year.
- 4
Fix the setter never called
easy8 minThe day was read without ever being changed.
- 5
Fix the minutes read as seconds
easy8 minThe wrong getter gives the wrong part.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace