var counter = 0; function show_counter () {alert(counter)}; function plus_counter () { counter = (counter+1)%3; show_counter (); }; plus_counter ()