Issue: I have two arrays, one representing Alice's scores and the other Bob's scores. The task is to compare the scores at each index for both players and award a point to the player with the higher score (no points if the scores are equal).
INPUT:
x = [4,1,6]
y = [1,1,5]
EXPECTED OUTPUT:
{Alice:2, Bob: 0}
MY CODE:
x = [4,1,6]
y = [1,1,5]
results = {'Alice':0, 'Bob': 0}
for (var i = 0; i < x.length; i++){
for (var j = 0; j < y.length; j++){
if (x[i] > y[j]){
results['Alice'] += 1
}else if (x[i] < y[j]){
results['Bob'] += 1
}
}
}
console.log(results)
ACTUAL OUTPUT:
{Alice: 5, Bob: 2}
QUESTION:
What mistake did I make in my code?