Skip to content

Commit 34c2a01

Browse files
Merge pull request #14 from AzharAli-github/main
Main
2 parents e3a014e + 15891ba commit 34c2a01

File tree

5 files changed

+123
-0
lines changed

5 files changed

+123
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
body {
2+
display: flex;
3+
justify-content: center;
4+
min-height: 97vh;
5+
}
6+
7+
.InpForm {
8+
border: 1px solid black;
9+
display: flex;
10+
flex-direction: column;
11+
width: 30%;
12+
align-self: center;
13+
padding: 30px 20px;
14+
line-height: 30px;
15+
}
16+
17+
.InpForm button {
18+
width: 20%;
19+
display: flex;
20+
justify-content: center;
21+
align-self: center;
22+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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>Errors</title>
9+
<link rel="stylesheet" href="css/style.css">
10+
</head>
11+
12+
<body>
13+
<div class="InpForm">
14+
<h2>JavaScript try catch</h2>
15+
<p>Please input a number between 5 and 10:</p>
16+
<input id="demo" type="text"><br>
17+
<button type="button" onclick="myFunction()">Test Input</button>
18+
<p id="p01"></p>
19+
</div>
20+
<script src="js/script.js"></script>
21+
</body>
22+
23+
</html>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// let Inpt = document.querySelector('#demo');
2+
// let button = document.querySelector('.button');
3+
// let message = document.querySelector('#message')
4+
5+
function myFunction() {
6+
const message = document.getElementById("p01");
7+
message.innerHTML = "";
8+
let x = document.getElementById("demo").value;
9+
try {
10+
if (x.trim() == "") throw "is empty";
11+
if (isNaN(x)) throw "is not a number";
12+
x = Number(x);
13+
if (x > 10) throw "is too high";
14+
if (x < 5) throw "is too low";
15+
} catch (err) {
16+
message.innerHTML = "Input " + err;
17+
} finally {
18+
document.getElementById("demo").value = "";
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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>Scope</title>
9+
</head>
10+
11+
<body>
12+
<h1>There are Three Types of Scope</h1>
13+
<h2>1.Block Scope</h2>
14+
<h2>2.Function Scope</h2>
15+
<h2>3.Global Scope</h2>
16+
<h3>(Open console and JS file for better Understanding )
17+
</h3>
18+
<script src="js/script.js"></script>
19+
</body>
20+
21+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* There are three type of Scope:
2+
1.Block Scope
3+
2.Golbal Scope
4+
3.Functional Scope
5+
6+
Two main scopes let and const which are block scope were introduced after ES6
7+
8+
*/
9+
10+
// First we will discuss Block Scope
11+
12+
var a = 2;
13+
console.log(a);
14+
15+
let b = 3;
16+
console.log(b);
17+
18+
const c = 4;
19+
console.log(c);
20+
21+
22+
// Now we will discuss about Functional Scope
23+
24+
function Scope() {
25+
let d = 3; //In functional scope the variable are declared inside the function and cannot be accessed outside
26+
console.log(d);
27+
}
28+
29+
// Global Scope
30+
31+
let e = 9; // In Global Scope variables are Global they can accessed inside a function and anywhere in the Program
32+
33+
function Display() {
34+
console.log(e);
35+
}
36+
console.log(e);
37+
// Do not try to use Global Scope Unless you intend because your global variables and functios can overwrite the window

0 commit comments

Comments
 (0)