...

View Full Version : Newbie Problems again



Mechlar
08-13-2005, 04:03 AM
Yet I am back again I have a simple assignment that I am having problems with. I am really struggling with functions. I will give my assignment description and my actual code. Maybe someone can look at what I am doing wrong and explain it to me and not just give me the answer. Thanks for any that help!
The Description:


In this project, you will create a script with a function that returns a string value.
1. Create a new document in your text editor.
2. Type the <!DOCTYPE> declaration, <html> element, document head, and
<body> element. Use the Strict DTD and “Company Name” as the content of
the <title> element.
3. Create a script section in the document head that contains the following
getCompanyName() function:
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function getCompanyName() {
var companyName = "Course Technology";
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
4. Modify the getCompanyName() function so that it returns the company name
to another calling function.

5. Add statements after the getCompanyName() function definition that call the
getCompanyName() function and assign the return value to a variable named
retValue.
6. Finally, wr ite code that prints the contents of the retValue var iable.
7. Save the document as CompanyName.html in the Projects folder for Chapter 3
and validate it with the W3C MarkUp Validation Service.
8. Open the CompanyName.html document in your Web browser.
9. Close your Web browser window.


My code so far:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Company Name</title>
<script type="text/javascript">
<!--Hide from incompatible browsers
function getCompanyName()
{
var companyName = "Course Technology";
return retValue;
}
//Stop hiding from browsers -->
</script>
</head>
<body>
<script type="text/javascript">
<!--Hide from incompatible browsers
var retValue = getCompanyName;
document.write(retValue);
</script>
</body>
</html>

Mechlar
08-13-2005, 04:59 AM
I guess sometimes a make a ant hill into a mountain. Here is a solution:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Company Name</title>
<script type="text/javascript">
<!--Hide from incompatible browsers
function getCompanyName()
{
var companyName = "Course Technology";
return companyName;
}
//Stop hiding from browsers -->
</script>
</head>
<body>
<script type="text/javascript">
<!--Hide from incompatible browsers
var retValue = getCompanyName();
document.write(retValue);
</script>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum