title: JavaScript Arrays and loops math
body: <p>I need to find the sum of the elements in the array ends. Also I need to find the middle number of the array elements, if the list of elements is odd display the middle number. If the list of elements is even I need the average of the two middle numbers. I've been at it for a long time and I just can't think anymore.</p>
  
  <pre><code>      &lt;!DOCTYPE HTML&gt;
        &lt;html lang="en-us"&gt;
        &lt;meta charset="utf-8"&gt;
  
        &lt;head&gt;
  &lt;title&gt;Functions With Arrays&lt;/title&gt;
  &lt;script type="text/javascript"&gt;
      /*Write a defining table and a function that returns the sum of the first and last values in an array. The function must have this header: function addEnds(list)*/
  
      /*Input: No input from user.
        Process: Calls the addEnds function to add the ends of the array.
        Output: Displays the sum of the array ends.
       */
  
      // This function calls the addEnds function and the getMiddle function.
      function multipleFunctions() {
          var list = ["10", "20", "30", "40", "50"];
          var result = 0;
          var result2 = 0;
          var result3 = 0;
          result = addEnds(list);
          result2 = getMiddle(list);
          result3 = "The sum of the array ends is " + result + "." + "&lt;br&gt;" + "The middle value of the array is " + result2 + ".";
          document.getElementById("outputDiv1").innerHTML = result;
      }
      // This function adds the ends of the array index values.
      function addEnds(list) {
          var sum = list[0] + list[4];
          return sum;
      }
  
      /*Write a defining table and a function that returns the value of the middle element in an array.  If the array has an even number of elements, then this function must return the average of the two middle elements.The function must have this header:function getMiddle(list)*/
      function getMiddle(list) {
          var middle = list[x];//don't know how...
              var evenOrOdd = list % 2;
          // Odd number of elements. 
          if (list !== 0)
              return list[middle];
      }
    // Even number of elements. 
      if (list === 0)
     return list[x] + list[x] / 2;//don't know how...
      }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h1&gt; Array list: 10, 20, 30, 40, 50&lt;/h1&gt;
  &lt;h2&gt;Click the compute function button to return the sum of the first and last values in the array list.&lt;br&gt; It will also return the average of the two middle elements of the array list.&lt;/h2&gt;
  &lt;button type="button" onclick="multipleFunction()"&gt;Compute Functions&lt;/button&gt;
  &lt;div id="outputDiv1"&gt;&lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>