-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path12 If Statements.html
29 lines (26 loc) · 1.12 KB
/
12 If Statements.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
<html lang="en">
<head><title> If Statements</title>
<!-- >
Conditional Statements
Very often when you write code, you want to perform different actions for different decisions.
You can use conditional statements in your code to do this.
In JavaScript we have the following conditional statements:
Use if to specify a block of code to be executed, if a specified condition is true
Use else to specify a block of code to be executed, if the same condition is false
Use else if to specify a new condition to test, if the first condition is false
Use switch to specify many alternative blocks of code to be executed
<-->
</head>
<body>
<script type="text/javascript">
var x=2; // try for x=1;
//checking if x equal to 1
if(x==1){
document.write("<h2>x is 1</h2>"); // if x==1 this line will print
}
else{ // if above statement is wrong then else will be execute
document.write("<h2><em>x is not 1</em><h2>")
}
</script>
</body>
</html>