The cycle time interval in setInterval is incorrect.

clipboard.png

what all the above JS code wants to achieve is that the text text changes every 2 seconds, but after each poll of the focusText array, that is, when text changes from "EXPLORE" to "TIME", the interval will exceed 2 seconds. Why?

Mar.13,2021

the array is out of bounds. It should be

.
iPP
if (i >= focusText.length) {
 i = 0
}

// i<focusTexti[0, 1, 2, ..., focus.length][0, 1, 2, ..., focus.length - 1]
if (i < focusText.length - 1) { 
 iPP
}

looked at the previous answer and seemed to miss the point.

=

The behavior of

setInterval is to queue the callback function at regular intervals. When the callback function can be executed depends on the previous code execution time.

ideally, if there is no executing code before, then the callback function can be executed immediately, but even then the time is not exactly 2 seconds, it is always a little more

.

this is a logic error. The scope of your I is [0, focusText.length] , not [0, focusText.length) . Feel that the code does not run as you want console.log , print debugging information is the most basic debug method.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5e0ef-45789.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5e0ef-45789.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?