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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    can som1 please explain what this script does

    hi could someone explain what this script will do? and how it works thanks

    <html>
    <head>
    <title>Function Example</title>
    <script LANGUAGE="JavaScript" type="text/javascript">
    function Average(a,b,c,d) {
    result= (a+b+c+d)/4;
    return result;
    }
    </script>
    </head>
    <body>
    <p>the following is the result of the function call. </p>
    <script LANGUAGE="JavaScript" type="text/javascript">
    score= Average(3,4,5,6);
    document.write("The average is: " + score);
    </script>
    </body>
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Is it not entirely obvious?

    It calculates the average (meaning the arithmetic mean) of four numbers which are passed to the function as variables a,b,c and d. Here the four numbers are 3,4,5 and 6 and the mean is 18/4 = 4.5.

    Note that <script LANGUAGE="JavaScript"> is deprecated and obsolete. Use <script type = "text/javascript"> instead.


    Edit: Please do not post any more homework assignmements in this forum. It is against the rules.



    Quizmaster: If something in dispute is divided equally, it is referred to as splitting the ... what?
    Contestant: Atom.
    Last edited by Philip M; 05-10-2009 at 04:34 PM.

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    but this isnt a homework assignment. You could say that everyone who posts here is doing that aswell

  • #4
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Well could you then, just for laughs, explain, in which real life application you stumbled upon this snippet, why it is so important to you to understand what it does, and, lacking any coding experience, how you got yourself into that situation in the first place.

  • #5
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by deldel View Post
    but this isnt a homework assignment. You could say that everyone who posts here is doing that aswell
    No, just the users that post questions like "explain this entire script to me". Others are posting code they've worked on that they can't quite get right.

  • #6
    New to the CF scene
    Join Date
    May 2009
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    well sorry i didnt kno it was such a problem to explain what something does. It doesnt have to be homework. I only wanted to understand it

  • #7
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Great, here you go: http://www.w3schools.com/jS/js_intro.asp

    If you still have trouble understanding a particular line in that script after reading through the basic chapters, ask and you will be helped.


  •  

    Posting Permissions

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