Bootcamp
Searchโฆ
Bootcamp
Welcome to Bootcamp!
๐
Logistics
๐
General Reference
๐
Projects
0: Language and Tooling
1: Frontend Basics
1.0: Module 1 Overview
1.1: HTML
1.2: DOM Review
1.3: High Card DOM
1.4: setTimeout
1.5: High Card setTimeout
1.6: Match Game
1.7: setInterval
1.8: Timer
1.9: Tic Tac Toe
1.10: Multi-File Refactor
1.11: CSS Control with DOM
1.ICE: In-Class Exercises
1.POCE: Post-Class Exercises
๐
CSS
2: Backend Basics
3: Backend Applications
4: Backend Structure
5: Full-Stack Applications
6: Frontend Infrastructure
7: React
8: Advanced React
9: Advanced Topics
๐งฎ
Algorithms
๐ผ
Interview Prep
โบ
User Experience
Powered By
GitBook
1.7: setInterval
Introduction
setInterval
repeats a callback function indefinitely at a designated interval until stopped.
Infinite Example
1
console
.
log
(
'starting...'
);
2
โ
3
const
delayInMilliseconds
=
1000
;
// this is one second
4
โ
5
const
ref
=
setInterval
(()
=>
{
6
console
.
log
(
`
I happen after
${
delayInMilliseconds
}
`
);
7
},
delayInMilliseconds
);
8
โ
9
console
.
log
(
'bananas!'
);
Copied!
Example that Stops
1
console
.
log
(
'starting...'
);
2
โ
3
const
delayInMilliseconds
=
1000
;
// this is one second
4
let
counter
=
0
;
5
โ
6
const
ref
=
setInterval
(()
=>
{
7
console
.
log
(
`
I happen after
${
delayInMilliseconds
}
`
);
8
console
.
log
(
counter
);
9
counter
+=
1
;
10
โ
11
if
(
counter
>
10
)
{
12
clearInterval
(
ref
);
13
}
14
},
delayInMilliseconds
);
15
โ
16
console
.
log
(
'bananas!'
);
Copied!
Exercise
Run the above code.
Previous
1.6: Match Game
Next
1.8: Timer
Last modified
2mo ago
Copy link
Contents
Introduction
Infinite Example
Example that Stops
Exercise