I need assistance comparing the elements of two arrays, array1 and array2. If element at position i in array1 is greater than that in array2, increment A by 1. If element at position i in array1 is less than that in array2, increment B by 1. Loop through all elements in both arrays and then output the total sum of A + B using console.log. I'm a beginner in JavaScript and would appreciate any help provided.
const X= [5,8,7,8];
const Y= [3,6,10,10];
let A = 0;
let B = 0;
for (var i=0; i < X.length; i++){
if(X[i] > Y[i]) {
A++;
}
else if (X[i] < Y[i]) {
B++;
}
}
console.log(`A: ${A}, B: ${B}`);