Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var enteredNumbers = [1,2,3,4,5,6,7,8,9,10];
- //You must use a parameter in order to hand the variables to the function, otherwise it won't take in any values.
- function exercise07Part1(array) {
- // 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.
- var total = 0;
- for(var counter = 0; counter < enteredNumbers.length; counter++){
- if(counter < enteredNumbers.length){
- total += enteredNumbers[counter];
- }
- }
- //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.
- return total;
- }
- // The line below literally translates to
- // #outputPart1's innerHTML = total
- // since you are handing off the total from the function.
- document.getElementById('outputPart1').innerHTML = exercise07Part1(enteredNumbers);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement