This demo increments a counter once per second and resets it to zero after reaching the configured cycle length. The expression (counter + 1) % cycleLength performs the wrap-around.
const cycleLength = 30;
let counter = 0;
setInterval(() => {
counter = (counter + 1) % cycleLength;
}, 1000);Back to remainder tutorial Alternate-item remainder demo
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.