+ 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);

16th Aug 2018, 11:39 AM
Kingsley Aham
Kingsley Aham - avatar
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
16th Aug 2018, 12:29 PM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar
+ 4
thanks for the explanation
18th Aug 2018, 12:31 PM
Kingsley Aham
Kingsley Aham - avatar