You were NOT using balls.length but num_balls instead!
num_balls
for (let i = 0; i < num_balls; i++) {