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
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding functions

    I hope that I don't annoy some people by posting this here, it's pretty basic, but I am learning Javascript from a website, and I have just gotten finished reading about Javascript Functions, and this is a pretty cool website that gives you assignments to do, and this particular assignment tells me to write a function that will add two numbers together at any place on the page.
    This is what I typed:
    <html>
    <head>
    <script language="javascript"><!--
    function myAdder(){
    var total= 23+56
    document.write(total) }
    //--></script>
    </head>
    <body>
    <SCRIPT language="JavaScript">
    <!--
    document.write(myAdder(23,56))
    //-->
    </SCRIPT>
    </body>
    </html>
    when I go to look at the result, I get 79undefined. What is undefined? I have tried alot with this script, so know that I don't come here as soon as I fail at something......Can somebody please find it deep deep deep down in their big heart to help me with this? Thanks in advanced
    -Chaseinchrist

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    The 79 is from the document.write in the head section.
    The undefined is from the document.write in the body.

    Try it like this

    PHP Code:
    <html>
    <
    head>

    <
    script type="text/javascript">
    <!--
    function 
    myAdder(a,b){
    var 
    totala+b
    return total
    }
    //-->
    </script>

    </head>
    <body>

    <script type="text/javascript">
    <!-- 
    document.write(myAdder(23,56))
    //-->
    </SCRIPT>
    </body>
    </html> 
    or this

    PHP Code:
    <html>
    <
    head>

    <
    script type="text/javascript">
    <!--
    function 
    myAdder(){
    var 
    total23+56
    document
    .write(total)
    }
    //-->
    </script>

    </head>
    <body>

    <script type="text/javascript">
    <!-- 
    myAdder()
    //-->
    </SCRIPT>
    </body>
    </html> 
    Last edited by Mr J; 06-01-2006 at 12:03 AM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    Mr. J:

    Can you recommend a good free online javascript tutorial for those of us whose brain freezes up when we see the words "var" and "node?"

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marilynn.fowler
    Mr. J:

    Can you recommend a good free online javascript tutorial for those of us whose brain freezes up when we see the words "var" and "node?"
    I am using this website, if you are interested in that. I really like it because he types each lesson in a personal tone, so it's not just directions. After each "Class" he gives you an assignment that you have to complete on your own time. I'm only on lesson 5, and there are 14 lessons in all, but you gotta be willing to spend your time reading through it, you can't just skim, or you'll be really confused at the end of the lesson(saying from experience).
    And thank you very much Mr. J for the help!
    Last edited by chaseinchrist; 06-01-2006 at 12:37 AM.

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    San Francisco
    Posts
    455
    Thanks
    19
    Thanked 15 Times in 15 Posts
    thanks! I'm starting to use it now.
    EDIT:
    I like this one. My eyes haven't glazed over yet.
    Last edited by marilynn.fowler; 06-04-2006 at 01:34 AM.

  • #6
    Regular Coder
    Join Date
    Sep 2005
    Location
    Chicago, IL
    Posts
    160
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This site also has some good tutorials: http://javascriptkit.com/javatutors/index.shtml
    I'm only telling you how I would do it, not how its supposed to be done. ;)


  •  

    Posting Permissions

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