-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprograms.html
More file actions
286 lines (215 loc) · 6.37 KB
/
programs.html
File metadata and controls
286 lines (215 loc) · 6.37 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
//🟨1. Creating Boolean Variables:
let isTrue = true
let isFalse = false
console.log(isTrue)
console.log(isFalse)
//🟨2. Boolean Expressions:
let age = 18
let isAdult = age >= 18
console.log(isAdult)
//🟨3. Comparison Operators:
let x = 5
let y = 10
let isEqual = x === y
let isNotEqual = x !== y
let isGreater = x > y
let isLess = x < y
console.log(isEqual)
console.log(isNotEqual)
console.log(isGreater)
console.log(isLess)
//🟨4. Logical Operators (AND, OR):
var hasPermission = true
var isLoggedIn = false
letAccessResource = hasPermission && isLoggedIn
letSeeContent = hasPermission || isLoggedIn
console.log(letAccessResource)
console.log(letSeeContent)
//🟨5. Negation Operator (NOT):
var isLoggedOut = !isLoggedIn
console.log(isLoggedOut)
//🟨6. Using Boolean Values in Conditional Statements:
var isRaining = false
if (isRaining) {
console.log("Take an umbrella")
} else {
console.log("No need for an umbrella")
}
//🟨7. Converting Values to Booleans:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var value1 = Boolean(0)
var value2 = Boolean("")
var value3 = Boolean(null)
var value4 = Boolean("Hello")
console.log(value1)
console.log(value2)
console.log(value3)
console.log(value4)
//🟨8. Using Booleans with If-Else Statements:
var isSunny = true
if (isSunny) {
console.log(isSunny + " It's a sunny day!")
} else {
console.log(isSunny + " It's not a sunny day! ")
}
//🟨9. Checking for Empty Strings:
let username = ""
if (username) {
console.log(`Hello ${username}`)
} else {
console.log("Please enter your username !")
}
//🟨10. Checking if a Number is Even:
let number = 9
let isEven = number % 2 === 0
if (isEven) {
console.log(`${number} is Even`)
} else {
console.log(`${number} is Odd`)
}
//🟨11. Using Ternary Operator:
let userName = "deep"
let isAuthenticated = true
var message = isAuthenticated ? `Welcome ${userName}` : "Acess Denied!"
console.log(message)
//🟨12. Checking for Multiple Conditions:
let isMorning = true
let isWeekend = false
if (isMorning && !isWeekend) {
console.log("It's a weekend morning")
} else {
console.log("It's either not mornign or it's the weekend.")
}
//🟨13. Using Boolean Functions:
function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0
}
var year = 2025
let leapYear = isLeapYear(year)
if (leapYear) {
console.log(`${year} is leap year`)
} else {
console.log(`${year} is not a leap year`)
}
//🟨14. Comparing Strings:
let color1 = "blue"
let color2 = "red"
let areColorSame = color1 === color2
if (areColorSame) {
console.log(`${color1} and ${color2} is Same`)
} else {
console.log(`${color1} and ${color2} are not Same`)
}
//🟨15. Checking if a Year is a Century Year:
function isCentureYear(year) {
return year % 100 === 0
}
var year = 2110
var isCentury = isCentureYear(year)
if (isCentury) {
console.log(`${year} is a century year`)
} else {
console.log(`${year} is not a century year`)
}
//🟨16. Using Logical OR to Provide Default Values:
function greetUser(username) {
username = username || "Guest"
console.log(`Hello, ${username}`)
}
greetUser("deep")
greetUser()
//🟨17. Checking if an Array is Empty:
let fruits = []
if (fruits.length === 0) {
console.log("The array is empty")
} else {
console.log("The array is not empty")
}
//🟨18. Checking if a Password Meets Criteria: >=8 char, >=1 Uppercase, >=1 digit
let password = "abc123"
let isStrongPassword = password.length >= 8 && /[A-Z]/.test(password) && /\d/.test(password)
if (isStrongPassword) {
console.log(`${password} is Srtong`)
} else {
console.log(`Password : "${password}" is Weak`)
}
//🟨19. Using Logical NOT for Validation:
function isValidInput(input) {
return !!input // 🟩Double negation converts the input to a Boolean
}
let userInput = "Hello"
if (isValidInput(userInput)) {
console.log(`User Input : "${userInput}" is Valid`)
} else {
console.log(`User Input : "${useInput}" is not valid`)
}
//🟨20. Checking if a Character is a Vowel:
function isVowel(char) {
char = char.toLowerCase()
return "aeiou".includes(char)
}
let letter = "a"
if (isVowel(letter)) {
console.log(`Letter : "${letter}" is Vovel`)
} else {
console.log(`Letter : "${letter}" is not a Vovel`)
}
//🟨21. Checking if a Number is Positive or Negative:
function isPositive(num) {
return num >= 0
}
var num = -5
if (isPositive(num)) {
console.log(`Number : '${num}' is Positive`)
} else {
console.log(`Number : '${num}' is Negative`)
}
//🟨22. Checking if a String Contains a Substring:
let sentence = "Deep Kothari"
let subString = "Deep"
if (sentence.includes(subString)) {
console.log(`subString : '${subString}' is present in sentence '${sentence}'`)
} else {
console.log(`subString : '${subString}' is not present in sentence '${sentence}'`)
}
//🟨23. Using the && Operator with Multiple Conditions:
var isSunny = true
var isWarm = true
if (isSunny && isWarm) {
console.log("It's sunny and warm outside!")
} else {
console.log("It's not sunny and warm outside")
}
//🟨24. Checking if a User Has Admin Rights:
let isAdmin = true
let canEdit = false
if (isAdmin || canEdit) {
console.log("The user can edit content")
} else {
console.log("The user can not edit content")
}
//🟨25. Using the ! Operator to Toggle a Boolean:
let isActive = false
// isActive = !isActive
// console.log("Active status : ",isActive)
// OR
if (isActive) {
console.log("User is active")
} else {
console.log("User is not active")
}
//🟨26. Using Conditional (Ternary) Operator for Simplified Code:
let isLogged = true
var message = isLogged ? "Welcome!" : "Please log in."
console.log(message)
</script>
</body>
</html>