...

View Full Version : How do I?



michshelly
01-29-2006, 03:20 AM
Hi, Can someone please tell me or explain to me how I would get Course Rules to print to the screen as the variable "company2" and Course Guidelines to print to the screen as the variable "company3", please?

<html>
<head>
<title> Praci </title>

<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS

function print_company_name(company1, company2, company3) {
document.write("<p>" + company1 + "</p>");
document.write("<p>" + company2 + "</p>");
document.write("<p>" + company3 + "</p>");
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>

<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS

print_company_name("Course Technology");

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</body>
</html>

This is what prints to the screen:

Course Technology
undefined
undefined

How do I get rid of undefined and have Course Rules and Course Guidelines?

Thanks
Michelle

A1ien51
01-29-2006, 04:00 AM
You are calling the function with one parameter. The other two parameters are then undefined. Hence it is being written to the page that way. So you nee to put the other values in there

print_company_name("Course Technology","asdf","qwerty");

Eric

michshelly
01-29-2006, 04:28 AM
Hi Eric,

Thanks for your reply. That did help me. However, how can I stop the "undefined" from printing to the screen?

Learning these functions is very hard! I spent last week learning functions, Data Types and the Window Object and one week over Christmas. I don't want to go any further until I really understand the functions. I wonder if I will ever learn it?

Thanks again
Michelle

Lerura
01-29-2006, 06:04 PM
function print_company_name(company1, company2, company3) {
document.write("<p>" + company1 + "</p>");
if (company2){document.write("<p>" + company2 + "</p>");}
if (company3){document.write("<p>" + company3 + "</p>");}
}

the if's will ensure that the script only will execute the document.write inside IF you have given the variable a value.

if (variable) actually means "if variable has a non-null-value".

null-values are:

undefined : assigned by the script if it cant find any definition of the variable.

null : special value that you can assign to a variable. telling the script that the variable should exist; but have no initial value.

false : either assigned directly as the value , or the negative result of a test (the test has failed because the conditions were not met).

michshelly
01-30-2006, 12:26 AM
Hello Lerura,

Thanks for your reply. Silly me, the 'if' statements didn't even occur to me. I have learnt it but for some reason I forgot about it. Same with 'if else' etc.

Thanks again
Michelle

glenngv
01-30-2006, 02:58 AM
if (variable) actually means "if variable has a non-null-value".

null-values are:

undefined : assigned by the script if it cant find any definition of the variable.

null : special value that you can assign to a variable. telling the script that the variable should exist; but have no initial value.

false : either assigned directly as the value , or the negative result of a test (the test has failed because the conditions were not met).
You have to add the numerical value 0 as one of those internally casted to false when used in conditions.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum