-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path12-nestingConditions.html
37 lines (31 loc) · 1.09 KB
/
12-nestingConditions.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
<!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 nesting if/else and comparison operators
var apple = 20;
var orange = 99;
var cherry = 99;
if (apple != orange) {
if (orange == cherry) {
document.write('I have ' + (orange + cherry) + ' oranges and cherries!');
} else {
document.write('I have ' + (apple + orange + cherry) + ' apples, oranges and cherries in my basket');
}
}
// short hand for nesting complex conditions
if ((apple < orange) && (orange == cherry)) {
document.write('I got fruit!');
}
// shorthand for OR condition
if ((apple < orange) || (apple == orange)) {
document.write('I have apples and oranges');
}
</script>
</body>
</html>