Javascript find the average from user's input using array?


#1

This is my code:

<html>
<head> Grade Average
<title> </title>
<script>
function dosomething
{
  var i = Number;
   
 var numbers = new Array{a,b,c};
        numbers[0] = a;
        numbers[1] = b;
        numbers[2] = c;

 var total=0;
  
    for (i=0; i<=numbers.length()-1; i++) 
   
    { total += numbers[i];
     var avg = total/numbers;
     
    }
    document.getElementById("functionOutput").innerHTML = numbers[i];
}
    </script>
    </head>
    
    <body>
     <p id= "functionOutput"></p>
        
    <input type="text" id="input" />
        
    <input type= "button" id="enter" onclick="dosomething(input.value)" 
    value="Calculate" />
        
    </body>
    </html>

#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.