JavaScript Simplified / Chapter 45 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.


Are you ready to rate JavaScript Simplified? on Amazon?


Rate it on Amazon.

0,1,2,3,4,5,6,7,8,9

0

0

0

0

You want to set the year of a Date object. What is the keyword? setFullYear setFullYear
What is the keyword for setting the smallest unit of time in a Date object? setMilliseconds setMilliseconds
The Date object is held in the variable d. Set it for the first day of the month. d.setDate(1); d\.setDate\(1\);
The Date object is held in the variable deadline. Set it to midnight. Don't set minutes, seconds, or milliseconds. deadline.setHours(0); deadline\.setHours\(0\);
The Date object is held in the variable d. Set it to February. d.setMonth(1); d\.setMonth\(1\);
Set a Date object to the last second. Make up the variable for the Date object. d.setSeconds(59); [a-z_$][a-zA-Z0-9_$]*\.setSeconds\(59\);
Set a Date object to the last hour of the day. Make up the variable for the Date object. aDate.setHours(23); [a-z_$][a-zA-Z0-9_$]*\.setHours\(23\);
Set a new time for a Date object that was originally "January 1, 2000 09:33:00". Set it 9 minutes earlier. Make up the variable for the Date object. dDay.setMinutes(24); [a-z_$][a-zA-Z0-9_$]*\.setMinutes\(24\);
  1. Create a Date object for the current date and time.
  2. Extract the hours.
  3. Set the time an hour later.
  4. Display the date Object in an alert.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, an alert will display the Date object set to an hour later.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 45 in the book.
  1. Create a Date object for the current date and time.
  2. Set it a century earlier.
  3. Display the date Object in an alert.
  4. Click the Result button (or, after revising, don't click, just wait).
  5. Wait a moment.
  6. If you've coded correctly, an alert will display the Date object set to a century earlier.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 45 in the book.