Skip to content
Exercise · Array methods · lesson 9 of 12

Exercise: sum of even squares

Write a function function sumEvenSquares(nums) that returns the sum of the squares of the even numbers in the array nums.

  • sumEvenSquares([1, 2, 3, 4]) → 20
  • sumEvenSquares([1, 3, 5]) → 0
  • sumEvenSquares([-3, -2]) → 4

Constraints: nums holds 0 to 10 integers from -100 to 100; negative numbers and 0 can be even too; for an empty array and an array with no even numbers the result is 0.

Do not add extra imports unless the task says so explicitly.

squares.js — javascript
javascript · 4 lines
Ctrl+Enter run · Esc leave editor

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way