Skip to the content

Add up the evens

Problem

Write a function that takes a list of whole numbers and returns the sum of the ones that are even. If there are none, return 0.

Examples

  • [1, 2, 3, 4] → 6

  • [] → 0

  • [1, 3, 5] → 0

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def sum_evens(numbers):
    pass

JavaScript

function sumEvens(numbers) {
}
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n) challenges

See all challenges →