/    Sign up×
Community /Pin to ProfileBookmark

Hey guys, I’m new to Javascript and I have a few simple problems that I can’t figure out. The problems require me to copy from the textbook and run it through the validator on w3, then correct the errors. However, I keep getting problems that I have no idea how to solve. I look through the chapter in my book, but I can’t come up with anything. For the first problem, I’m getting error messages like:

Error Line 20, Column 20: document type does not allow element “ul” here

document.write(“<ul>”);

(the > is underlined and in red, as well as the ” in another message)

Line 21, Column 38: character data is not allowed here

document.write(“<li>Eat less fat</li>”)

(the last ” is underlined and red)

I know these are probably very simple problems for you guys, but I’m stuck and have no idea on how to correct them. Any help is appreciated.

[CODE]
<!DOCTYPE html PUBLIC
“-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Dietary Recommendations</title>
<meta http-equiv=”content-type” content=”text/html; charset=iso-8859-1″ />
</head>
<body>
<h1>Dietary Recommendations</h1>
<p>The American Heart Association recommends the following dietary guidelines for a healthy heart:</p>
<script type=”text/javascript”>
/* <![CDATA[ */
/*
Joshua Meadors
10/24/2012
Exercise 1-6
*/
/* ]]> */
document.write(“<ul>”);
document.write(“<li>Eat less fat</li>”)
document.write(“<li>Avoid sugary and processed foods</li>”)
document.write(“<li>Eat plenty of fiber-rich foods</li>”)
document.write(“<li>Cut down on salt</li>”)
document.write(“<li>Eat at least 400g of fruit and vegetables each day</li>”)
document.write(“<ul>”);
</script>

</body>
</html>
[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@jlm990authorOct 26.2012 — Could a mod please erase my last name in the code? It's on line 15, but I can't edit my post. Thanks
Copy linkTweet thisAlerts:
@ReFreezedOct 27.2012 — The CDATA section should cover all of the code in your script element:

&lt;script type="text/javascript"&gt;
//&lt;![CDATA[

All your JavaScript code here...

//]]&gt;
&lt;/script&gt;


Right now the validator thinks there's an actual <ul> element inside your JavaScript code as it doesn't know that that code is part of the script - it just sees everything as HTML. The CDATA prevents that from happening.
Copy linkTweet thisAlerts:
@jlm990authorOct 29.2012 — That works perfectly. Thank you.
Copy linkTweet thisAlerts:
@JavaboeyOct 30.2012 — You're also not closing out your <ul>. The last line should say document.write("</ul>"); You missed the "/".
×

Success!

Help @jlm990 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...