Advertisement
sinithwar

Untitled

May 1st, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var enteredNumbers = [1,2,3,4,5,6,7,8,9,10];
  2. //You must use a parameter in order to hand the variables to the function, otherwise it won't take in any values.
  3. function exercise07Part1(array) {
  4.     // You cannot have total be an empty variable. Since there is no instantiated(starting) value, the program will not know where it needs to add from, which is zero in this case.
  5.     var total = 0;
  6.     for(var counter = 0; counter < enteredNumbers.length; counter++){
  7.          if(counter < enteredNumbers.length){
  8.                 total += enteredNumbers[counter];
  9.           }
  10.     }
  11.     //In order to do anything with the values made in here, you must return the end(resulting) value of the for loop so that the function utilizing this for loop will be able to have access to the value. Otherwise, it's basically telling the program to do this work and then not telling it who to hand it off to.
  12.     return total;
  13. }
  14. // The line below literally translates to
  15. // #outputPart1's innerHTML = total
  16. // since you are handing off the total from the function.
  17. document.getElementById('outputPart1').innerHTML = exercise07Part1(enteredNumbers);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement