Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: How do I?

  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I?

    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
    Last edited by michshelly; 01-29-2006 at 04:22 AM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Undefined

    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

  • #4
    Regular Coder Lerura's Avatar
    Join Date
    Aug 2005
    Location
    Denmark
    Posts
    947
    Thanks
    0
    Thanked 130 Times in 129 Posts
    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).

  • #5
    New Coder
    Join Date
    Dec 2005
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by lerura
    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.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •