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

1. ## 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

• 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>
<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;
margin:30px;
}
-->
</style>

<script type="text/javascript">
<!--
var nums=new Array(1,2,3,4,5,6,7,8,9,10);
var temp=0;
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>

<body>

<div id="numbers"></div>

</body>
</html>```

• 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.

• 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.

• "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.

• 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.

• “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.

• 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'.