0

Can anyone please say what these numbers are. They are increasing so fast. Is that the no of times the function executes?

var time = setInterval(function() {
    var b = document.getElementsByTagName('a')[22].innerHTML;
    if (b == "name") {
        document.getElementsByTagName('a')[22].click();
        clearInterval(time);
    } else {
        console.log("sript started");
    }
}, 10);

enter image description here

Sumner Evans
  • 8,951
  • 5
  • 30
  • 47
Sparrow
  • 65
  • 2
  • 10
  • 1
    It's the number of times in a row that a message has been sent to the console. If that is your message and it is only sent to the console when 1 of your functions has been called, then yes it is the number of times it has been executed (since any other message has been sent to the console) – DvideBy0 Oct 18 '16 at 03:39
  • @DvideBy0 you should have posted an answer. – Soviut Oct 18 '16 at 03:40
  • @DvideBy0 Thanks. All i wanted to do is to automate the buying of mobile in flash sale by clicking the__Buy Now__ button as soon as it appears on the screen. My another doubt is to choose between a while-loop or a if-block. While is for repetitively checking for button. If is for clicking button as soon as it appears. – Sparrow Oct 18 '16 at 04:00

2 Answers2

3

Those are the number of times the console.log("Script Activated") message has been triggered. Chrome automatically groups consecutively identical log messages rather than write it out each one on a new line. This makes it easier to see previous messages that would normally get scrolled off the top of the console too quickly.

In your case, the interval's callback function is triggering the log message every 10 milliseconds, so it's increment that count very quickly because it will occur 100 times a second.

EDIT: In a comment on another answer you asked why setting the interval value to 10000000000 caused the interval to go extremely quickly, rather than once every ~115 days.

This is because the number exceeds the maximum size a signed 32-bit integer can be is aproximately 2.1 billion (2,147,483,647). Once it exceeds that amount, it "wraps" around to the negative numbers. When setInterval() receives a negative number for the interval milliseconds, it simply rounds the value up to 4 milliseconds. This results in the interval occurring as quickly as possible, about 1000 times a second. I say "about" because there is no guarantee it will go this quickly on slower hardware.

Soviut
  • 88,194
  • 49
  • 192
  • 260
  • Isn't the function not triggering for every 10 milliseconds in my code – Sparrow Oct 18 '16 at 03:40
  • I would include that it is only the number of consecutive times since another message has been posted. – DvideBy0 Oct 18 '16 at 03:42
  • Updated to mention consecutive log messages. – Soviut Oct 18 '16 at 03:43
  • What I wanted to make is to trigger that call in the _if_ block every 10 milliseconds – Sparrow Oct 18 '16 at 03:50
  • Regarding your edit, the minimum possible interval/timeout is 5ms isn't it? (Lower values are rounded up.) – nnnnnn Oct 18 '16 at 03:55
  • That's exactly what your code is doing. It keeps firing your `console.log` message because `b` doesn't equal `"name"`. – Soviut Oct 18 '16 at 03:55
  • @nnnnnn I've updated my answer. Turns out the value is 4ms. – Soviut Oct 18 '16 at 03:57
  • @Sparrow this question thoroughly answers your question, so you should mark it (or another similar answer) correct. If you have more questions about why your code isn't working, ask a new question on SO. – Soviut Oct 18 '16 at 03:58
  • http://stackoverflow.com/questions/7648557/setinterval-behaviour-with-0-milliseconds-in-javascript – Sparrow Oct 18 '16 at 04:08
0

It's console.log() output's times. log one time show num 1, log two times show num 2.

Frank
  • 928
  • 8
  • 15
  • if i put it as 10, the number frequency is 1000 per 1second. If i put it as 10000000000 it is increasing very rapidly. – Sparrow Oct 18 '16 at 03:43
  • 1
    @Sparrow that's because the number is too large for a 32 bit browser and the signed integer is "wrapping" to a negative number. When `setInterval()` encounters a negative number, it assumes 0, which will trigger once per millisecond or browser repaint. – Soviut Oct 18 '16 at 03:47