Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Collect Evens (continue)

Fundamentals: Part 2medium

Course · Section 3: JavaScript Fundamentals – Part 2 · Lecture 48: Looping Arrays, Breaking and Continuing

Implement `collectEvens(arr)` returning the even numbers, using a for loop and `continue` to skip odds.

Sample tests

Input: collectEvens([1,2,3,4,5,6])
Output: [2,4,6]
Input: collectEvens([1,3])
Output: []

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Using break would stop the loop entirely.
Visualize this concept: Truthy and Falsy Values →
Approach & explanation (try first)

continue skips odd numbers so only evens are collected.

Loading...
⌘/Ctrl + Enter

Run your code to see results.