As the title says, I am trying to take an array of numbers, and then return the sum of all the even numbers in the array squared.
I can get my function to return the sum of all the even numbers in a given array, but cannot get it to square the sum of the even numbers.
Here is what I have so far:
let numStr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const squareEvenNumbers = (numStr) => {
let sum = 0;
for (let i = 0; i < numStr.length; i++) {
if (numStr[i] % 2 === 0) {
sum = Math.pow(sum + numStr[i], 2);
}
}
return sum
}
console.log(squareEvenNumbers(numStr));