Skip to content

Commit aecf692

Browse files
timing
1 parent 8034a3a commit aecf692

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>timing-events JS</title>
9+
<link rel="shortcut icon" href="images/js-logo.png" type="image/x-icon">
10+
<link rel="stylesheet" href="style.css">
11+
</head>
12+
13+
<body>
14+
<h1>Timing events in JS</h1>
15+
<h2>SetTimeout</h2>
16+
<p id="textOne"></p>
17+
<h2>ClearTimeout</h2>
18+
<button onclick="DisplayTwo()">Start</button>
19+
<button onclick="StopTwo()">Stop</button>
20+
<p id="textTwo"></p>
21+
<h2>SetInterval</h2>
22+
<p id="textThree"></p>
23+
<h2>ClearInterval</h2>
24+
<button onclick="DisplayFour()">Start</button>
25+
<button onclick="StopFour()">Stop</button>
26+
<p id="textFour"></p>
27+
<script src="script.js"></script>
28+
</body>
29+
30+
</html>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Timing in JavaScript adds interactivity to function that how much time will it take to load
3+
a function, after how many time will the function display or clear:
4+
We will discuss some of the timing constraints in JavaScript:
5+
1. SetTimeout(function(){}, 1000()
6+
*/
7+
let textOne = document.getElementById('textOne');
8+
9+
setTimeout(function DisplayOne() {
10+
textOne.innerHTML = "Hi There!"
11+
}, 2000);
12+
13+
// Now we will discuss the second method of timimg which is
14+
// 2. clearTimeOut(function(){}, 1000) : This is used for stoping the execution
15+
16+
let textTwo = document.getElementById('textTwo');
17+
18+
function DisplayTwo() {
19+
x = setTimeout(function() {
20+
textTwo.innerHTML = "Hello after Three Second!"
21+
}, 3000);
22+
return x;
23+
}
24+
25+
function StopTwo() {
26+
clearTimeout(x)
27+
alert("You have stopped the operation")
28+
}
29+
30+
// I loved working in the above code now next is..
31+
// 3. setInterval(function(){}, miliseconds)
32+
33+
let textThree = document.getElementById('textThree');
34+
35+
function DisplayThree() {
36+
setInterval(function() {
37+
textThree.innerHTML = "HELLO Example 3 here after 2 Seconds"
38+
}, 2000)
39+
}
40+
DisplayThree();
41+
42+
43+
// Our Next Topic is clearInterval
44+
45+
let textFour = document.getElementById('textFour');
46+
47+
function DisplayFour() {
48+
y = setInterval(function() {
49+
textFour.innerHTML = "EXAMPLE FOUR HERE!";
50+
}, 3000)
51+
}
52+
53+
function StopFour() {
54+
clearInterval(y);
55+
alert("You have Stoped Example Four Operation!")
56+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
h1 {
2+
font-family: sans-serif;
3+
}
4+
5+
h2 {
6+
font-family: monospace;
7+
}
8+
9+
p {
10+
font-family: Arial, Helvetica, sans-serif;
11+
}

0 commit comments

Comments
 (0)