Results 1 to 3 of 3
Thread: Please help me with arrays!
- 08-10-2009, 07:39 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 1
- Rep Power
- 0
Please help me with arrays!
I have an assignment due on tuesday and i'm having a few problems with arrays. First I can't seem to get my array to display vertically, it just comes out like 12,34,67,ect. also I'm having difficulty getting the highest and lowest number from the array. My program is supposed to get temperatures from the user and calculate the average, sum, high and low and list all the input. This is what i have so far
[code]
<script language="JavaScript">
var tempInputArray=new Array();
function addToStats() {
var tempInput=document.tempStats.tempInput.value;
tempInputArray.push(tempInput);
var sum=parseFloat(0);
for(i=parseFloat(0); i<tempInputArray.length; i++)
sum+=parseFloat(tempInputArray[i]);
var average=sum/tempInputArray.length;
var max=tempInputArray[0];
for(i=parseInt(1); i<tempInputArray.length; i++)
if(tempInputArray[i]>max {
max=tempInputArray[i];
}
output=(tempInputArray + "<br>");
document.getElementById("output").innerHTML=output
output1=("The # of entries is " + tempInputArray.length + " and the sum is " + sum + "<br>" + "The average is " + average + "<br>" + "The largest is " + max);
document.getElementById("output1").innerHTML=outpu t1
}
function clearForm() {
output="";
document.getElementById("output").innerHTML=output ;
output1="";
document.getElementById("output1").innerHTML=outpu t1;
document.tempStats.tempInput.value="";
}
</script>
[code]
Any help would be greatly appreciated!:D
-
Your code shows this to be a JavaScript program while this is a Java forum, and the two programming languages are only related by name and by sharing a c-based syntax, but otherwise are completely different. You\'ll likely have better luck getting help from a true JavaScript forum. Best of luck.
- 08-10-2009, 04:30 PM #3
Similar Threads
-
Help with arrays!
By lilac87 in forum New To JavaReplies: 2Last Post: 07-28-2009, 04:57 AM -
Help!! With arrays
By ookie833 in forum New To JavaReplies: 8Last Post: 12-14-2008, 12:57 AM -
Arrays
By TheRocket in forum New To JavaReplies: 6Last Post: 12-10-2008, 06:00 PM -
2D Arrays
By Major90 in forum New To JavaReplies: 6Last Post: 11-06-2008, 02:08 PM -
2D-Arrays
By kbyrne in forum New To JavaReplies: 1Last Post: 02-07-2008, 10:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks