+ 10
Given a question like what is the answer and please explain.
var arr = [2,5,2,4]; var x = 1; for(var i = 0; i < arr.length; i++) { if(arr[i]%2 === 0) x *= arr[i]; } document.write(x);
2 Respuestas
+ 4
The above code calculates the product of all even numbers in the given array.
arr[i] % 2 === 0
// arr[i] is even.
document.write(x)
// Output: 2 * 2 * 4 = 16
+ 4
thanks for the explanation