-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path11-ifElseConditions.html
More file actions
44 lines (38 loc) · 1.51 KB
/
11-ifElseConditions.html
File metadata and controls
44 lines (38 loc) · 1.51 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Demo</title>
</head>
<body>
<script type="text/javascript">
// Fun with if/else and comparison operators
var apple = 20;
var orange = '20';
var space = '</br>';
// when comparing use `===` (strict) is equal to
// this will also make sure your values are of the same type
// Example: a string equals a string or an integer equals an integer
// If you used just '==', apple and orange would be equal
// Using just '==' you would get true when comparing 0 == ''
if (apple === orange) {
document.write('Apples are equal to oranges' + space)
} else {
document.write('Apples and oranges, not equal' + space)
}
// if apple IS NOT EQUAL to orange
if (apple !== orange) {
document.write('Apples do not equal oranges' + space)
} else {
document.write('Apples and oranges, living happy together' + space)
}
// compare actual values
if (apple >= orange) {
document.write('Apples are greater then or equal to oranges' + space)
} else if (apple <= orange) {
document.write('Apples are less then or equal to oranges' + space)
}
</script>
</body>
</html>