The variable "zmot" is NOT initialized anywhere. Try using var zmot = 0; instead of var zmot;