title: How do I return the sum of all values in an array?
body: <p>I am very new to javascript and am having a problem figuring out if I should use <code>return</code> or <code>document.write</code> or both to return the sum of all values in an array called 'amount'.  I am supposed to create a function names amountTotal().</p>
  
  <p>The purpose of which is to return the sum of all values in the <code>amount</code> array.  Then I am to declare a variable named <code>total</code>, setting its initial value to 0. Then create a for loop that loops through all the values in the <code>amount</code> array.</p>
  
  <p>At each iteration of the loop, add the current value of the array item to the value of the <code>total</code> variable. Finally, after the loop is completed I need to return the value of the <code>total</code> variable. The largest array value is <code>[34]</code>. This value will be written to a table called <code>Summary</code></p>
  
  <p>This is what I have written so far.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function amountTotal() {
          var total = 0;
          for (i = 0; i &lt; 35; i++) {
              document.write("&lt;td&gt;" + i + "&lt;/td&gt;")
          }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Am I on the right track?</p>