javascript using global variables -
can't seem work.
var current_times = new date(); var future_times = new date(); function time(){ current_times = current_times.setminutes(current_times.getminutes()); future_times = future_times.setminutes(future_times.getminutes() + 1); } error im getting is: current_times.getminutes not function
note sure helps, time function called function initiated on body load.
the problem setminutes returns number, not date object.
the function work first time call it, on second call current_times , future_times numbers, , hence won't have getminutes function. since setminutes() modifies date object instead of producing new one, solution not reassign variables.
furthermore, if understand intentions correctly, code can simplified to:
var current_times, future_times = new date(); function time() { current_times = new date(); future_times.setminutes(current_times.getminutes() + 1); }
Comments
Post a Comment