Chapter 11 - Answers

Question 11.1

  1. Object-Based programming language
  2. Attributes, behaviors
  3. Math
  4. Sending a message to the object
  5. Double quotation marks, single quotation marks
  6. 0
  7. indexOf, lastIndexOf
  8. tokenization
  9. Computer's local time zone, Coordinated Universal Time (UTC).
  10. Parse
  11. LocalStorage
  12. sessionStorage
  13. :first-child
  14. :nth-child

Question 11.2

  1. Create a web page that contains four buttons. Each button, when clicked, should cause an alert dialog to display a different time or date in relation to the current time.Create a Now Button that alerts the current time and date and a Yesterday button that alerts the time and date ten years ago and one week from today.

Question 11.3

  1. Write a script that test as many of the Math library functions in Fig. 11.1 as you can.

Question 11.4

  1. Math method floor may be used to round a number to a specific decimal place.
    For example, the statement
    y = Math.floor( x * 100 + .5) /10;
    rounds x to the tenths postion. Write a script that defines four funxtions to round a number x in various ways:
  2. Round To Integer ( number)
  3. Round To Tenths( number )
  4. Round To Hundredths( number )
  5. Roud To Thousandths( number )
  6. Enter the number you want rounded with Math.floor:

Question 11.5

  1. Modify the solution to Exercise 11.4 to use Math Method round instead of mathod floor.
  2. Enter the number you want rounded with Math.round:

11.6

  1. Write a script that uses relational and equality operator to compare two Strings input by the user through an HTML5 form.
    Display whether the first string is less than, equal to or greater than the second.
  2. Enter String 1:
  3. Enter String 2: