Chapter 315mChallenge

JavaScript Functions — Challenge

Reusable blocks of code.

This content is not yet available in si. Showing English version.

View in English →

Apply what you've learned. Each challenge includes starter code and test cases.

Sum of Array

medium

Sum of Array

Given const nums = [1, 2, 3, 4, 5], print the sum of all numbers using .reduce().

Expected Output

text
15
STARTER CODE
const nums = [1, 2, 3, 4, 5];
// Use .reduce() to sum all numbers
1 test cases
Start Challenge

Filter Even Numbers

medium

Filter Evens

Given const nums = [1, 2, 3, 4, 5, 6, 7, 8], use .filter() to print only the even numbers as an array.

Expected Output

text
[2,4,6,8]
STARTER CODE
const nums = [1, 2, 3, 4, 5, 6, 7, 8];
// Filter even numbers and console.log them
1 test cases
Start Challenge