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 8 of 8

Thread: Arrays

  1. #1
    New to the CF scene
    Join Date
    Jul 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrays

    HI,

    sorry this is such a basic question -

    I have an array of 10 numbers, i need to print the first number and then add the second number and print the total, i then need add the 3rd number and print the total - etc until the end of the ten numbers -

    eg 1 1
    2 3
    3 6
    4 10etc

    thanks for any ideas -
    Johnr

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,718
    Thanks
    0
    Thanked 240 Times in 235 Posts
    Hi there johnr100,

    and a warm welcome to these forums.

    does this help...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    <!--
    #numbers {
        width:100px;
        font-family:monospace;
        border:1px solid #000;
        padding:10px;
        margin:30px;
     }
    -->
    </style>
    
    <script type="text/javascript">
    <!--
       var nums=new Array(1,2,3,4,5,6,7,8,9,10);
       var temp=0;
    window.onload=function() {
    for(c=0;c<nums.length;c++) {
       temp=temp+nums[c];
    if(nums[c]<10) {
       nums[c]='0'+nums[c];
     }
       document.getElementById('numbers').innerHTML+=nums[c]+'. '+temp+'<br />';
      }
     }
    //-->
    </script>
    
    </head>
    <body>
    
    <div id="numbers"></div>
    
    </body>
    </html>
    coothead
    Last edited by coothead; 07-06-2006 at 05:39 AM.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,146
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    I am sure that johnr100's teacher will be most impressed at the spped at which he has leaned such sophistication! But sadly if he simply copies other peoples' work he will never learn, and in future every time he gets the answer right the teacher will suspect that he has cheated. In the long run it is unhelpful and counter-productive to do students' homework for them.

  • #4
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,718
    Thanks
    0
    Thanked 240 Times in 235 Posts
    Hi there Philip,

    you will probably tell me that I am obtuse but how do you differentiate between students and non students.
    I can only see people with problems.

    coothead

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    "If you fish for a man you feed him for a day. If you teach him to fish you feed him for life." (I can't remember who said that but it is very relevant).

    If you teach people how to write the code themselves instead of writing it for them then it doesn't matter whether the person is a student or not.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,718
    Thanks
    0
    Thanked 240 Times in 235 Posts
    Hi there felgall,

    alternatively...

    'He who can, does. He who cannot teaches'

    George Bernard Shaw

    I am only here to try and solve problems. If this is right or wrong, it is not for me to say.
    I will leave that to those with the problems.

    coothead

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,146
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    “Give a man a fish; you have fed him for today. Teach a man to fish; and you will not have to listen to his incessant whining about how hungry he is.”—Author unknown

    “Give a man a fish; you have fed him for today. Teach a man to fish; and you can sell him fishing equipment.”—Author unknown

    “Give a man a fish; you have fed him for today. Teach a man to use the Internet and he won't bother you for weeks.”—Author unknown

    “Teach a man to fish and you feed him for a lifetime. Unless he doesn't like sushi—then you also have to teach him to cook.”—Auren Hoffman, Herald Philosopher

    “Give a man a fish; you have fed him for today. Teach a man to fish, and he will sit in the boat and drink beer all day.”—OldFox

    “Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime. Teach a man to sell fish and he eats steak.”—Author unknown

    Coothead - I see you are in Chertsey, which is not a thousand miles away from me.

  • #8
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,718
    Thanks
    0
    Thanked 240 Times in 235 Posts
    Hi there Philip,
    ... I see you are in Chertsey, which is not a thousand miles away from me.
    Oh my gosh, I hope that does not mean that, I will be getting the 'middle of the night bang on the door'.

    coothead


  •  

    Posting Permissions

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