Try replacing var with let. When using var, all onClick handlers reference the same variable that retains its final value after loop completion.
var
let
onClick