0%
Checking the code runner…

Instructions

Lesson 3 of 4

Arrays and Loops

An array is an ordered list of values:

for...of

for...of visits every item in an array:

The classic counting loop works too:

filter and map

Arrays have built-in methods that take a function. filter keeps items that pass a test, and map transforms each item:

Exercise: Only the evens

Write evens(numbers) that returns a new array with only the even numbers, in their original order.

Your turn!

Write your code in and press Submit answer.

  • console.log(JSON.stringify(evens([1, 2, 3, 4]))); → [2,4]
  • console.log(JSON.stringify(evens([7, 9]))); → []
  • plus 1 hidden check

Help

Hint

A number is even when n % 2 === 0. Try numbers.filter(...), or loop with for...of and push into a new array.

Pass the exercise to complete this lesson.

Terminal
Press Run to see your output here.