-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCC-4.js
30 lines (27 loc) · 859 Bytes
/
DCC-4.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
/*-----------------------------------------------------------------
Challenge: 04-addList
Difficulty: Basic
Prompt:
- Write a function called addList that accepts any quantity of numbers as arguments, adds them together and returns the resulting sum.
- Assume all parameters will be numbers.
- If called with no arguments, return 0 (zero).
Examples:
add(1) //=> 1
add(1, 50, 1.23) //=> 52.23
add(7, -12) //=> -5
Hint: Check out the Further Study section of the JS Functions lesson regarding "rest parameters"
-----------------------------------------------------------------*/
// Your solution for 04-addList here:
const addList = (...nums) => {
let total = 0
if (nums === undefined){
return 0
}
else {
for(let num = 0; num < nums.length; num++){
total += nums[num]
}
return total
}
}
console.log(addList(5, 10, 11)) //=> 26