JavaScript Simplified / Chapter 46 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're creating a Date object for the first day of the first month of the year 2000. Fill in the blank. let prevDate = new Date(______________); "January 1, 2000" •January1,2000•
What is the keyword for extracting the basic time unit you need for calculating milliseconds? getTime getTime
Code a statement that creates a Date object for the last day of the last month of 2030 and assigns it to later, which hasn't been declared beforehand. let later = new Date("December 31, 2030"); letlater=newDate\(•December31,2030•\);
Code a statement that creates a Date object for 1 minute past midnight, New Year's Day, 2015, and assigns it to kissEnds, which has been declared beforehand. kissEnds = new Date("January 1, 2015 00:01:00"); kissEnds=newDate\(•January1,201500:01:00•\);
Create a Date object for the first second of the first day of the first month of 1901 and assign it to a variable that hasn't been declared beforehand. let earlyTime = new Date("January 1, 1901 00:00:01"); letearlyTime=newDate\(•January1,190100:00:01•\);
Code a single statement that displays in an alert the milliseconds that elapsed between the reference date and the beginning of 1980. alert(new Date("January 1, 1980").getTime()); alert\(newDate\(•January1,1980•\)\.getTime\(\)\);
Code a statement that converts the milliseconds represented by ticks to hours and assigns the result to a variable that hasn't been declared beforehand. Make up the variable name. let hrs = ticks / 1000 / 60 / 60; let[a-z_$][a-zA-Z0-9_$]*=ticks\/1000\/60\/60;
Code the first line of an if statement that tests whether the milliseconds represented by ms convert to more than 30 days. if (ms / 1000 / 60 / 60 / 24 > 30) { if\(ms\/1000\/60\/60\/24>30\){
  1. Create a Date object for your current date and time.
  2. Extract the month, day of month, and year.
  3. Display them 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 current month, day of month, and year.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 46 in the book.
  1. Create a Date object for your current day and time.
  2. Extract the number of milliseconds since the reference date of January 1, 1970.
  3. Display an alert that converts the milliseconds into days. Round it up to an integer.
  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 days that have elapsed since the reference date.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 46 in the book.