K
K
Kusmich2015-10-19 10:00:03
JavaScript
Kusmich, 2015-10-19 10:00:03

Why is the display function not working?

There is a function that takes a number from an array and breaks it into numbers. Then passes the values ​​to the calculation function. Which takes the first value from the array and makes a miscalculation.

For example, if the value in the array is 3 , it considers 1,2,3. And there is a display function that should display the last number and intermediate values. But it only displays a finite number.

Tell me where am I making a mistake?

Here is the code:

var numbers = [27389, 13948, 59835, 39843, 17263]; // массив с которого
 берем значения

 var stnum_1;

 function replaceNum(i) { // проход по массиву цыклом
if (i < 0 || i >= numbers.length) {
    return;

};       

var digits = (numbers[i] + "").split(""); // разбиваем массив

stnum_1 = digits[0]; // сохраняем новое значение

setTimeout(function() { replaceNum(i + 1); }, 2000); // переход к другому     элементу массива 

};
replaceNum(0);

 var cur = 1;
 if (cur > 0) {
var count = 0;
var interval = 1000;

var refresh = function() {

// получаем значение из нового массива и делаем просчет 
while (StateStnum_1!= stnum_1) {
StateStnum_1++;
if(StateStnum_1 > 9){StateStnum_1 = 0;}

console.log(StateStnum_1);

};

   // переменная StateStnum_1 содержит данные для отображения просчета
        flip('hoursUp' + 1, 'hoursDown' + 1, StateStnum_1, 'Single/Up/' + 2 + '/', 'Single/Down/' + 1 + '/');

    setTimeout(function() {
    refresh();
    }, interval);
    };

    refresh();
    }


What is interesting is that there is a miscalculation through the console log, and from the display function, the current is the final values.

all in fiddle : https://jsfiddle.net/Valeriy1996/uk95046b/

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question