promlem displaying total of figures in javascript

  roundy 23:34 25 Feb 2005
Locked

can anybody help me as I am having problems with a section of my java script. I am trying to display a windows prompt which appears four times, once the figures have been entered I wish to have them displayed on separate lines then a total of these figures underneath. I can get the windows prompt figures to work but cannot get the total of these figures to be displayed underneath on screen. Here is the java script:
HTML>
HEAD>
TITLE>
/TITLE>
SCRIPT >



var rainArray = new Array (4);
var total

document.write('Array program to read in a known number of data items');
for (var month = 0; month rainArray.length; month = month + 1)
{
rainArray[month] = window.prompt('Enter rainfall value for month ' + (month + 1),')
};
document.write(' BR>' + ' BR>');
document.write('Confirmation of data input' + ' BR>' + ' BR>');

for (var month = 0; month rainArray.length; month = month + 1)
{
document.write(rainArray[month] + ' BR>')
}
total = parseFloat(total);
total = rainArray;
document.write('totoal amount is ' + total + ' BR>')

/SCRIPT>
/HEAD>
BODY>
/BODY>
/HTML>
Can anyone help?

  curlylad 01:07 26 Feb 2005

Glad you could join us here at PCA , sorry that nobody has offered help yet , perhaps some of the more technically minded java boffins will be along in the morning.

Come on guys you're letting me and roundy down here ! You see I work with him and explained that if he were to post his problem here then somebody would offer a solution in next to no time.It is his first posting as a new member so lets show him what PCA members can do , I cannot help so it is up to you guys now !

OK roundy , I've fought your corner for you a bit now it's up to 'them out there' !

  curlylad 01:47 26 Feb 2005

Click on my link and pose your question to this guy who claims to be very knowledgable in all things javascript click here= As I said earlier , some java boffins will be along in the morning so sit tight !

  smudge101 15:28 26 Feb 2005

You say you can get the prompts to work.
Could you please repost your html code for this as your code does not bring up the prompts?
Just cut & paste from the page you have working.

If you can put that code here I will have a look at it for you.

  roundy 00:39 27 Feb 2005

smudge101
Below is HTML java script code
<HTML>
<HEAD>
<TITLE>
</TITLE>
<SCRIPT >


var rainArray = new Array (4);
var total

document.write('Array program to read in a known number of data items');
for (var month = 0; month < rainArray.length; month = month + 1)
{
rainArray[month] = window.prompt('Enter rainfall value for month ' + (month + 1),')
};
document.write('<BR>' + '<BR>');
document.write('Confirmation of data input' + '<BR>' + '<BR>');

for (var month = 0; month < rainArray.length; month = month + 1)
{
document.write(rainArray[month] + '<BR>')
}
total = parseFloat(total);
total = rainArray;
document.write('totoal amount is ' + total + '<BR>')

</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

  smudge101 13:06 27 Feb 2005

Hi Roundy, sorry this took a while been a bit busy.

You where almost right, it does help to spread out your code so you can understand what is going on more easily.

Anyway, the code below works.

<HTML> <HEAD> <TITLE> </TITLE> <SCRIPT language=JavaScript>

var rainArray = new Array (4);
var total = 0

document.write('Array program to read in a known number of data items');
for (var month = 0; month < rainArray.length; month = month + 1)
{ rainArray[month] = window.prompt('Enter rainfall value for month ' + (month + 1),') };

document.write('<BR>' + '<BR>');
document.write('Confirmation of data input' + '<BR>' + '<BR>');

for (var month = 0; month < rainArray.length; month = month + 1)

{ document.write(rainArray[month] + '<BR>') }


for (var month = 0; month < rainArray.length; month = month +1)
total = total + parseFloat(rainArray[month]);

document.write('total amount is ' + parseFloat(total))

</SCRIPT> </HEAD> <BODY> </BODY> </HTML>

  smudge101 14:32 28 Feb 2005

This formatts the output a bit better.

<HTML> <HEAD> <TITLE> </TITLE>

<SCRIPT language=JavaScript>

var rainArray = new Array (4);

var total = 0

document.write('Array program to read in a known number of data items');


for (var month = 0; month < rainArray.length; month = month + 1)

{ rainArray[month] = window.prompt('Enter rainfall value for month ' + (month + 1),')};


document.write('<BR>' + '<BR>');

document.write('Confirmation of data input' + '<BR>' + '<BR>');


for (var month = 0; month < rainArray.length; month = month + 1)


{ document.write("Month " + (month + 1) + " = " + rainArray[month] + '<BR>') }



for (var month = 0; month < rainArray.length; month = month +1)
total = total + parseFloat(rainArray[month]);


document.write('<BR>' +'Total amount is ' + parseFloat(total))

</SCRIPT> </HEAD> <BODY> </BODY> </HTML>

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

HP Envy x2 review: Hands-on

Iconic New York graphic designer Milton Glaser on his uplifting new subway posters

New iMac Pro release date, UK price & specs rumours

Comment suivre le parcours du père Noël ?