View Single Post
Old 02-12-2013, 10:19 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Corrections made:
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>Two Functions</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
/* <![CDATA[ */
function printMessage(first_message) 
{
    document.write("<p>" + first_message + "</p>");
}
function return_message() 
{
   return "<p>This message was returned from a function.</p>";
}
/* ]]> */
</script>
</head>
<body>
<script type="text/javascript">
/* <![CDATA[ */
printMessage("This message was printed by a function.");
var return_value = return_message();
document.write(return_value);
/*]]> */
</script>
</body>
</html>
Note that in your post you had these lines:
Code:
return "<p>This message was returned from
a function.</p>");

printMessage("This message was printed
by a function.");
I can't tell if that's an artifact of how you posted or if your code is really like that.

If it's really like the, you need to know that a JavaScript string literal (text between quote marks) can *NOT* be broken across more than one line.

If the text is long, you must break it into two literal strings and concatenate them.

Example:
Code:
printMessage("This message was printed"
        + " by a function.");
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
jasonmcbee (02-13-2013)