9.5. Exercises

  1. Using the program from the Try It Out labeled "Identifying Errors By Number" earlier in the chapter, modify the logic so that the user verifies that she really wants to Cancel.

  2. After completing Exercise 1, give the user as many chances as needed to correctly type an integer value.

  3. Modify the getInteger handler developed in this chapter to accept two additional arguments that specify the minimum and maximum allowable values for the user to enter. So the statement

    set monthNumber to getInteger ("Enter a month number (1-12): ", 1, 12)

    calls the getInteger handler to prompt the user to enter a number between 1 and 12. The handler checks the value entered against the specified range, giving a message if the number falls outside the range.

    If the minimum value or maximum value is specified as a missing value, no minimum or maximum bound is desired. So the statement

    set monthNumber to getInteger ("Enter a positive number: ", 0, missing value)

    can be used to allow any positive integer to be entered.

  4. Instead of having the getInteger handler return missing value if a bad integer number is entered by the user, extend the answer from Exercise 3 to allow for an additional argument that specifies the maximum number of tries you give to the user before giving up.

  5. Write a program that determines the error number generated when you divide by zero (no peeking at the table!).

Get Beginning AppleScript® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.