forked from alpana-d/FLW1_CodingChallenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharraySum.js
45 lines (31 loc) · 763 Bytes
/
arraySum.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
~ DO IT SOLO ~
Write a function that finds the sum of all the numbers in an array. Print the result to the console
Test your code to check that it works for multiple inputs!!
Sample inputs & outputs:
#1
Input
numbers = [10, 20, 20, 30, 10, 6, 4]
Output
sum = 100
#2
Input
numbers = [10, 20, 30, -50]
Output
sum = 10
#3
Input
numbers = [10, -10, 20, -30, 50, -50]
Output
sum = -10
*/
let numbers = [1, 2, 3, 4, 5];
function findSum(numbers) {
// 1. Create a variable `sum` to store the sum of numbers
// 2. Write a for loop to iterate through the array
for(let i = 0; i<numbers.length; i++) {
// what goes here?
}
// 3. Print the sum of numbers to the console
}
// 4. Test that the code works for multiple inputs!