In this project, you create and fix a script that prints text strings.
1. Create a new document in your text editor.
2. Type the <!DOCTYPE> declaration, <html> element, header
information, and the <body> element. Use the strict DTD and
”Babe Ruth“ as the content of the <title> element.
3. Add the following script section to the document body:
<script type="text/javascript">
/* <![CDATA[ */
/* ]]> */
</script>
4. Add the following statements to the script section:
document.write("<p>Babe Ruth was also known as
the "Bambino" and the "Sultan of Swat."</p>");
5. Save the document as BabeRuth.html in your Exercises
folder for Chapter 8, and then open it in your Web browser.
You should receive an error message about a missing paren-
thesis. The problem with the code is that the string in the
document.write() statement contains nested double quota-
tion marks. To fix the problem, you need to escape the double
quotation marks with a backslash character.
6. Return to the BabeRuth.html document in your text
editor, and add escape characters to the string in the
document.write() statement, as follows:
document.write("<p>Babe Ruth was also known as
the \"Bambino\" and the \"Sultan of
Swat\".</p>");
7. Save the BabeRuth.html document, and then validate the
document with the W3C Markup Validation Service. Once
the document is valid, close it in your text editor and reload
it in your Web browser window. The text should be displayed
correctly without any error messages.
8. Close your Web browser window.
- 10 years ago
Purchase the answer to view it
- baberuth.html