-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTernary-operator.html
109 lines (92 loc) · 2.75 KB
/
Ternary-operator.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// let number = prompt("Enter the Vale of Number ");
// let result = ;
// if(number>0)
// {
// result += "Positive";
// }
// else{
// result += "Neagative";
// }
// console.log("The result is " + result);
// Ternary Operaor (Using Single if else)
// result = number > 0 ? "positive" : "Negative";
// console.log(result);
// console.log(number > 0 ? "positive" : "Negative");
// if(number > 0)
// {
// result = "positive ";
// if(number %2==0)
// {
// result +="Even";
// }
// else{
// result +="odd";
// }
// }
// else
// {
// if(number < 0)
// {
// result = "Negative ";
// if(number%2==0)
// {
// result +="Even";
// }
// else{
// result +="Odd";
// }
// }
// }
// console.log("Result is " + result);
// Ternary Operator Used with Nested If
// Method 1
// result= number > 0 ? ("Positive " + (number % 2 == 0 ? " Even" : " Odd")) : ("Negative" + (number % 2 == 0 ? " Even" : " Odd"));
// console.log(result);
// Method 2
// console.log( number > 0 ? ("Positive " + (number % 2 == 0 ? " Even" : " Odd")) : ("Negative" + (number % 2 == 0 ? " Even" : " Odd")));
let Std_RollNo = prompt("Enter the Student Roll Number ");
let check;
if(Std_RollNo >= 1 && Std_RollNo <= 50)
{
check = "Valid Student";
if(Std_RollNo >=1 && Std_RollNo <=20)
{
console.log("Student Belongs To Intelligent Iguanas");
if(Std_RollNo == 5)
{
console.log("And Prefect");
}
else{
console.log("And NOT Prefect");
}
}
else
{
console.log("Student Belongs To The simple Group ");
}
}
else
{
console.log("Invalid Choice waits for few minutes ");
}
// Ternary Operator
var result;
// a == 2 ? true : false;
result =
// Std_RollNo >=1 && Std_RollNo <= 50 ? "Valid Student " + Std_RollNo >= 1 && Std_RollNo <=20 ? "Student Belongs To Intelligent Iguanas" + Std_RollNo == 5 ? "And Prefect" :"Not Prefect" : "Roll Number is greater than 20": Std_RollNo >20 && Std_RollNo <=50 ? "Student Belongs To The Fantastic Four Group" + Std_RollNo == 35 ? "And Prefect" : "Not Prefect" : "Roll number out of range";
console.log(result);
Std_RollNo >=1 && Std_RollNo <=50 ? "Valid Student"
// If else Statement used for Decision Making
</script>
</body>
</html>