1.setTimeout() //executes the code after x seconds.
2.setInterval() //executes the code **every** x seconds.
1// .setTimeout() //executes the code after x seconds.
2// .setInterval() //executes the code **every** x seconds.
3
4function oneSecond() {
5 setTimeout(function () {
6 console.log("Sup!");
7 }, 2000); //wait 2 seconds
8}
9
10/*In this function, it executes a function every 1 second*/
11function stopWatch() {
12 setInterval(function () {
13 console.log("Oooo Yeaaa!");
14 }, 2000); //run this thang every 2 seconds
15}
16
17oneSecond();
18stopWatch();
1var intervalID = setInterval(alert, 1000); // Will alert every second.
2// clearInterval(intervalID); // Will clear the timer.
3
4setTimeout(alert, 1000); // Will alert once, after a second.
5setInterval(function(){
6 console.log("Oooo Yeaaa!");
7}, 2000);//run this thang every 2 seconds
1setTimeout() //executes the code after x seconds.
2.setInterval() //executes the code **every** x seconds.
1/*The difference between setTimeout() and setInterval() is that
2setTimeout() only executes code once, but setInterval() executes
3the code each amount of time you input. For example,*/
4
5/*In this function, it executes a function after 1000 milliseconds, or 1
6second.*/
7function oneSecond(){
8 setTimeout(1000, function(){
9 console.log('That was 1 second.')
10 })
11}
12
13/*In this function, it executes a function every 1 second*/
14function stopWatch(){
15 var count = 0;
16 setInterval(1000, function(){
17 console.log(count + " Seconds passed")
18 })
19}