K
K
Kusmich2015-10-19 12:46:50
JavaScript
Kusmich, 2015-10-19 12:46:50

How to execute a function after incrementing the value of a variable?

There is a function that increases the value of a variable by 1 . You need to somehow check whether the value of the StateStnum_1 variable has increased and then execute the function: flip('hoursUp' + 1, 'hoursDown' + 1, StateStnum_1, 'Single/Up/' + 2 + '/', 'Single/Down/' + 1 + '/');

Here is the code:

while (StateStnum_1!= stnum_1) {
         StateStnum_1++;
       
       flip('hoursUp' + 1, 'hoursDown' + 1, StateStnum_1, 'Single/Up/' + 2 + '/', 'Single/Down/' + 1 + '/');
       
  if(StateStnum_1 > 9){StateStnum_1 = 0;}
  
  console.log(StateStnum_1);
  
  
  
    };

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ihor Gevorkyan, 2015-10-19
@Kusmich

while (StateStnum_1 != stnum_1) {
    var oldState = StateStnum_1;
    StateStnum_1++;
    if (StateStnum_1 > oldState) {
        flip('hoursUp' + 1, 'hoursDown' + 1, StateStnum_1, 'Single/Up/' + 2 + '/', 'Single/Down/' + 1 + '/');
    }   
    if(StateStnum_1 > 9) {
        StateStnum_1 = 0;
    }
  console.log(StateStnum_1);
};

I did not check for performance, but, from how I understood what was needed, this should help

M
Maxim Grechushnikov, 2015-10-19
@maxyc_webber

execute the function every n seconds

A
Andrew, 2015-10-19
@R0dger

On the native, the idea only comes through setInterval.
on angularJs watch you can hang up and enjoy life.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question