-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconditionals.js
More file actions
166 lines (144 loc) Β· 4.13 KB
/
conditionals.js
File metadata and controls
166 lines (144 loc) Β· 4.13 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
* ------------------------- CONDITIONAL STATEMENTS ---------------------------
*/
// ----------------------------------------------------------------------------
/**
* TEST : Eligiblity check for voting
*/
// // Single if statement
// function EligiblityCheck(name,age){
// if (age >=18) {
// console.log(`${name}, You are eligible for voting!`)
// }
// }
// EligiblityCheck("Akash",30)
// // if-else ladder statement
// function EligiblityCheck(name,age){
// if (age < 18) {
// console.log(`${name}, You are not eligible for voting!`)
// }
// if(age >=18 && age <=65){
// console.log(`${name}, You are eligible for voting!`);
// }
// else
// if(age > 65){
// console.log(`${name}, You are eligible!`)
// }
// }
// EligiblityCheck("Akash",64)
// ----------------------------------------------------------------------------
/**
* TEST : Advanced eligibility check
*/
function EligiblityCheck(...arg){
let voterName = arg[0]
let age = arg[1]
if(arg.length == 1){
console.log("Kindly pass your age as second argument");
}
else
if(arg.length == 2){
if(typeof(voterName)=="string"){
if(age > 0){
if (age < 18) {
console.log(`${voterName}, You are not eligible for voting!`);
}
else
if(age >=18 && age <=65){
console.log(`${voterName}, You are eligible for voting!`);
}
else
if(age > 65){
console.log(`${voterName}, You are eligible!`);
}
}
else{
console.log("Please insert a valid age");
}
}
else{
console.log("Please pass your name as first argument");
}
}
else
if(arg.length > 2){
console.log(`You have passed ${arg.length} arguments.`);
}
}
// EligiblityCheck("Vikash", 20)
/**
* EligiblityCheck(_NAME_,_AGE_)
* Pass your name as first argument and your age as second argument
* You can try by passing only one or more than arguments as well as by not passing name as first arguemnt
*/
// ----------------------------------------------------------------------------
/**
* TEST : Workout schedule
*/
function workout(day){
let dayName = day.toUpperCase()
switch (dayName) {
case "SUN":
console.log("LEG WORKOUT DAY")
break;
case "MON":
console.log("LEG WORKOUT DAY")
break;
case "TUE":
console.log("REST")
break;
case "WED":
console.log("BICEP & BACK WORKOUT DAY")
break;
case "THU":
console.log("BICEP & BACK WORKOUT DAY")
break;
case "FRI":
console.log("CHEST WORKOUT DAY")
break;
case "SAT":
console.log("CHEST WORKOUT DAY")
break;
default:
console.log("PLEASE ENTER A VALID DAY.")
break;
}
}
// workout("FRI")
// workout("Thu")
/**
* NOTE : Enter a valid day name to get your workout schedule
*/
// ----------------------------------------------------------------------------
/**
* TEST : Get exponential values of any single or a range
*/
function power(...args) {
let [expo, start, end] = args;
if(args.length > 3){
console.log("Pass only 3 or less arguments");
}
else{
if (start != undefined && end != undefined) {
for (let i = Math.min(start , end); i <= Math.max(start, end); i++) {
console.log(`${i}^${expo}= ${Math.pow(i, expo)}`);
}
}
else
if(expo == undefined) {
console.log("Pass atleast two arguments");
}
else
if (start == undefined) {
console.log("Pass Second Argument");
}
else {
console.log(`${start}^${expo} = ${Math.pow(start, expo)}`);
}
}
}
power(2, 12, 1);
/**
* power(EXPONENT, START, END)
* You can get power value of any range or any order
*/