On Firefox, when you load the
ErrorDemoPage, you will see a blank browser window. When this happens
you can go to the Tools menu and select JavaScript Console.
When you do this a
window will be displayed. Scroll down to the last error
message: As you can see, the error message not only indicates the type of
error that occurred (e.g. "unterminated string literal") it also
indicates where the error occured. If you click on
the link beside "Source File", a window will open containing the source
for the page and the error will be highlighted. Note that you will not
be able to edit the source in this window. Instead, to correct the
error you will need to edit your original HTML document (using KWrite),
save it and
reload it in the browser.
Error:
unterminated string literal
Source File
http://www.gac.edu/~hvidsten/courses/MC170/ErrorDemoPage.html
document.write("Hello world);
---------------'
For the last part of this lab, you are to write a JavaScript Mad Lib. If you have never seen a Mad Lib before, the concept is pretty straightforward. A potentially humorous story is written down, with blanks in the place of some of the key words. Before reading the story, the storyteller asks others present to fill in those blanks. Those selecting the words are only told the type of word required, and have no other knowledge of the story. This lack of context in selecting words can result in an entertaining story when the words are plugged in to the appropriate places.
Consider a simple example:
It was a adjective kind of day when person's name walked out into the street. The sky was a deep color , and same name was walking his new pet animal ...
Making the following substitutions:
adjective = smarmy
person's name = Chris
color = mauve
animal = gnu
the story would read:
It was a smarmy kind of day when Chris walked out into the street. The sky was a deep mauve, and Chris was walking his new pet gnu ...
Now that you know how to create interactive Web pages using HTML and
JavaScript, you can write a simple page that generates Mad Libs.
To do this, you are to create a Web page that serves as an interactive
Mad Lib program. Your
page should contain JavaScript code that prompts the user for words to
fill in the blanks in a story, and then stores those words in
variables. Your code should then display the story in the Web page,
using the values of the variables where appropriate. Refer to
Chapter 4 for the basics of prompting the user for text and writing
text to a web document.
The content of the story can be anything that you like -- be creative! Your story must meet the following conditions, however.
- It must be at least two paragraphs long.
- It must have at least eight missing words.
- At least one of the missing words must be used multiple times in the story. For example, the person's name was used twice in the sample story above.
- The page should have a title, centered at the top, that includes your name.
Include the complete HTML source for your MadLib page as your answer for this exercise.
On my honor, I pledge that I have not given, received, nor tolerated others' use of unauthorized aid in completing this work.