Results 1 to 3 of 3
  1. #1
    ddrcan is offline Member
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Default 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  3. #3
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Location
    Chennai
    Posts
    431
    Rep Power
    6

    Default

    Does java-forums.org change into javascript-forums.org?
    Mak
    (Living @ Virtual World)

Similar Threads

  1. Help with arrays!
    By lilac87 in forum New To Java
    Replies: 2
    Last Post: 07-28-2009, 04:57 AM
  2. Help!! With arrays
    By ookie833 in forum New To Java
    Replies: 8
    Last Post: 12-14-2008, 12:57 AM
  3. Arrays
    By TheRocket in forum New To Java
    Replies: 6
    Last Post: 12-10-2008, 06:00 PM
  4. 2D Arrays
    By Major90 in forum New To Java
    Replies: 6
    Last Post: 11-06-2008, 02:08 PM
  5. 2D-Arrays
    By kbyrne in forum New To Java
    Replies: 1
    Last Post: 02-07-2008, 10:08 PM

Posting Permissions

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