forked from Minskoleopc/javascript830B
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script7.js
113 lines (82 loc) · 1.71 KB
/
script7.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
// ternary operator
let q = 8
let r = 4
q > r ? console.log('q is greater'):console.log("r is greater")
let age = 19
//age >= 18 ? console.log("can drive"):console.log("cannot drive")
let a = age >= 18 ? "can drive":"cannot drive"
console.log(a)
// switch case without break
let city = "bhopal"
switch(city){
case "pune":
console.log("MH")
case "jaipur":
console.log("RJ")
case "kanpur":
console.log("UP")
case "bhopal":
console.log("MP")
default:
console.log("Incorrect city name")
}
// program 2
let city2 = "Jaipur"
switch(city2){
case "nagpur":
console.log("MH")
break
case "kanpur":
console.log("UP")
break
case "jaipur":
console.log("RJ")
break
case "bhopal":
console.log("MP")
break
default:
console.log("Incorrect city name")
}
// program 3
let city3 = "jaipur"
switch(city3){
case "nagpur":
case "mumbai":
console.log("MH")
break
case "bhopal":
case "indore":
console.log("MP")
break
case "jaipur":
case "udaipur":
console.log("RJ")
break
default:
console.log("incorrect city name")
}
// program 4
let a1 = 1000
let a2 = 50000
let a3 = 300000
// if(a1 > a2 && a1 > a3){
// console.log("a1 is greater")
// }
// else if(a2 > a1 && a2 > a3){
// console.log("a2 is greater")
// }
// else {
// console.log("a3 is greater")
// }
let flag = true
switch(flag){
case a1 > a2 && a1 > a3:
console.log("a1 is greater")
break
case a2 > a1 && a2 > a3:
console.log("a2 is greater")
break
default:
console.log("a3 is greater")
}