An array is an ordered list of values. You can step through it with a for-in loop and inspect each element. This is your first building block.
Given an array of integers nums, return the sum of all the even numbers in it. If there are no even numbers, return 0.
Examples
▸ nums = [1, 2, 3, 4]
→ 6
▸ nums = [1, 3, 5]
→ 0
▸ nums = []
→ 0
Progressive Hints
Hint 1 · Nudge
The only numbers that count are the ones you can split in half with nothing left over.
Hint 2 · Plan
Keep a running total that starts at 0. Walk through every number in the array; when a number is even, add it to the total. After the loop, return the total.
Hint 3 · Approach
total = 0. For each n in the array: if n is even (n % 2 == 0) then total = total + n. Return total.
All hints are out. Take a breath and give it a shot.