Advertisement
AuriR

Beginning Programming - Example Function

Mar 1st, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sum(theNumbers) {
  2.   // Start with 0
  3.   var result = 0;
  4.  
  5.   // Now, for each number I have, put it in a variable named number
  6.   // and do something with it.
  7.   for(number: theNumbers) {
  8.     result = result + number;
  9.   }
  10.  
  11.   // Return the result.
  12.   return result;
  13. }
  14.  
  15. var numbers = [8,6,7,5,3,0,9];
  16.  
  17. var total = sum(numbers);
  18. print("Total is: " + total); // should return 38
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement