Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How do I simulate the view counter? - bug-code.com Q&A

How do I simulate the view counter?

0 like 0 dislike
65 views
How can I make a count of counters? Let's say there are two variables where the range from and to is set. And for example, every minute this number on the page will be updated within the range.
And you can somehow make the number by which the number is increased/decreased was not sharp. Let's say the range is 50 to 200 and first the random number is 75, and after one minute 200, so that plus or minus the previous value is for example 5, not such a big jump.
asked by (700 points) | 65 views

1 Answer

0 like 0 dislike

<span class="counter">100</span>
 

let counter = $('span.counter');

    setInterval(function () {

        let min = (Math.random() > 0.5) ? 0 : 5;
        let max = (Math.random() > 0.5) ? 5 : 10;

        let c = parseInt(counter.text());
        let r = Math.floor(Math.random() * (max - min + 1)) + min;

        if (Math.random() > 0.5) {
            counter.text(c + r);
        }

    }, 2000);
answered by (2.9k points)
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

12.7k users

24,788 questions
46,220 answers
0 comments
12,715 users