-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathif_else.js
110 lines (100 loc) · 2.04 KB
/
if_else.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var hello = 'hello';
if (hello == 'hello'){
console.log('this is true')
}
else{
console.log('this is false')
}
// Strict equal operator ===
var num1 = 10;
var str1 = '10';
// double equal operator convert type first(eval before comparison )
if (num1 == str1){
console.log("it's the same")
}
else{
console.log("it's not the same")
}
if (num1 === str1){
console.log("it's the same")
}
else{
console.log("it's not the same")
}
// inverse of equality operator
// - != is the inverse of ==
// - != = is the inverst of ===
function multipleCriteria(val){
if (val > 10 && val <20){
return 'yes'
}
else{
return 'false'
}
}
console.log(multipleCriteria(25))
function orStatement(val){
if (val < 10 || val > 20){
return true
}
else {
return false
}
}
console.log(orStatement(15))
function elseIf(val){
if (val > 10){
return 'greater than 10'
}
else if(val < 5) {
return 'less than 5'
}
else {
return 'between 5 and 10'
}
}
console.log(elseIf(7))
// chain if else statement
function chainIfElse(val){
if (val < 5){
return 'tiny'
}
else if (val < 10){
return 'small'
}
else if (val < 15){
return 'medium'
}
else if (val < 20){
return 'Large'
}
else {
return 'Humongous'
}
}
console.log(chainIfElse(100))
// switch statement, it's case when in sql
// adding else statement inside switch statement
// switch statement note, if you don't input break the code will just keep going and assign new answer value to your variable.
function testSwitch(val){
var answer = "";
switch (val){
case 1:
answer = 'alpha'
break;
case 2:
answer = 'beta'
break;
case 3:
answer = 'gamma'
break;
case 4:
answer = 'theta'
break;
default:
answer = 'mismatched input'
break;
}
return answer
}
console.log(testSwitch('hello'))