-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScope&Conditionals.html
71 lines (67 loc) · 2.31 KB
/
Scope&Conditionals.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scope and Conditionals</title>
</head>
<body>
<div>
<ul>
<li>Item-1</li>
<li>Item-2</li>
<li>Item-3</li>
<li>Item-4</li>
<li>Item-5</li>
<li>Item-6</li>
<li>Item-7</li>
</ul>
</div>
<script>
var str1 = "This is a string";
var str1 = "This is a string"; //Here value of var overrides
console.log(str1)
let a = 'u5'; //Here after using let you can't overide the variable
{
let a = 'u';
console.log(a) // Here value of a will change but for only this block --> {} outside this block a remains u5
}
const b = "This cannot be changed ";
console.log(b)
//Conditionals using switch
let age = 14;
if (age>18){
console.log('You can drink water');
}
else if (age==4){
console.log("Don't drink anything")
}
else if (age==14){
console.log("Don't drink anything")
}
else{
console.log('You can drink cold drink');
}
//Conditionals using if else
const cups = 43;
switch (cups) {
case 4:
console.log("The value of cups is 4") //If you don't put break after every statement like this then it will run all
break; // the test cases and print them rather than stopping and selecting one
case 41:
console.log("The value of cups is 41")
break;
case 42:
console.log("The value of cups is 42")
break;
case 43:
console.log("The value of cups is 43")
break;
default:
console.log("The value of cups is none of 4,41,42,43")
break;
}
</script>
</body>
</html>