Report the UTC hours of the date.
Acceptance criteria
- 1.#out should show 14.
JavaScript Tutorial · JavaScript Dates
These 10 tasks go with the JavaScript Date Components 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: “Getters read each part of a date, and setters change them.” .
1.Read the hoursexercise · easy · 10 min
Report the UTC hours of the date.
Passes when: #out should show 14.
2.Read the weekday numberexercise · easy · 10 min · practice plan
Report the weekday number, where Sunday is zero.
Passes when: #out should show 4.
3.Name the weekdayexercise · easy · 10 min · practice plan
Use an array to turn the number into a name.
Passes when: #out should show Thursday.
4.Change the yearexercise · easy · 10 min · practice plan
Set the year to 2027 and report it.
Passes when: #out should show 2027.
5.Build a padded timeexercise · medium · 10 min · practice plan
Show the time with leading zeros.
Passes when: #out should show 09:05.
6.Fix getDate used for the weekdaybug fix · easy · 8 min
getDate is the day of the month; getDay is the weekday.
Passes when: #out should show Thursday.
7.Fix the unpadded timebug fix · easy · 8 min · practice plan
Single digits need a leading zero.
Passes when: #out should show 09:05.
8.Fix the year set with the wrong methodbug fix · easy · 8 min · practice plan
setUTCMonth changes the month, not the year.
Passes when: #out should show 2027.
9.Fix the setter never calledbug fix · easy · 8 min · practice plan
The day was read without ever being changed.
Passes when: #out should show day is 20.
10.Fix the minutes read as secondsbug fix · easy · 8 min · practice plan
The wrong getter gives the wrong part.
Passes when: #out should show 30.
Between them these tasks cover Getters, Setters and Weekdays.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.