11.1 Fill in the blanks in each of the following statements:
- Because JavaScript uses objects to perform many tasks, JavaScript is commonly referred to as a(n) object-based programming language.
- All objects have attributes and exhibit behaviors.
- The methods of the Math object allow you to perform many common mathematical calculations.
- Invoking (or calling) a method of an object is referred to as sending a message to the object.
- String literals or string constants are written as a sequence of characters in double quotation marks or single quotation marks.
- Indices for the characters in a string start at 0.
- String methods indexOf and lastIndexOf search for the first and last occurances of a substring in a String, respectively.
- The process of breaking a string into tokens is called tokenization.
- String method link formats a String as a hyperlink.
- Date and time processing can be performed based on the computer's local time zone or on World Time Standard's Coordinated Universal Time (UTC).
- Date method parse receives as its argument a string representing a date and time, and returns the number of miliseconds between midnight, January 1, 1970 and the specified date and time.
11.7 Write a script that uses random number generation to create sentences. Use four arrays of strings called article, noun, verb and preposition. Create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article and noun. As each word is picked, concatenate it to the previous words in the sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period.
The arrays should be filled as follows: the article array should contain the articles "the", "a", "one", "some" and "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; the verb array should contain the verbs "drove", "jumped", "ran", "walked" and "skipped"; the preposition array should contain the prepositions "to", "from", "over", "under" and "on".
The program should generate 20 sentences to form a short story and output the results to an XHTML textarea. The story should begin with a line reading "Once upon a time..." and end with a line reading "THE END."
11.21 Write a program that reads a five-letter word from the user and produces all possible three-letter words that can be derived from the letters of the five-letter word. For example, the three-letter words produced from the word "bathe" include the commonly used words "ate", "bat", "bet", "tab", "hat", "the" and "tea." Output the results in an XHTML textarea.
11.22 (Printing Dates in Various Formats) Dates are printed in several common formats. Write a script that reads a date from an XHTML form and creates a Date object in which to store it. Then use the various methods of the Date object that converts Dates into strings to display the date in several formats.
11.29 (Project: Crossword Puzzle Generator) Most people have worked a crossword puzzle, but few have ever attempted to generate one. Generating a crossword puzzle is suggested here as a string-manipulation project requiring substantial sophistication and effort.
There are many issues you must resolve to get even the simplest crossword puzzle generator program working. For example, how does one represent the grid of a crossword puzzle in the computer? Should one use a series of strings, or use double-subscripted arrays?
You need a source of words (i.e. a computerized dictionary) that can be directly referenced by the program. In what form should these words be stored to facilitate the complex manipulations required by the program?
The really ambitious reader will want to generate the clues portion of the puzzle, in which the brief hints for each across word and each down word are printed for the puzzle worker. Merely printing a version of the blank puzzle itself is not a simple problem.