-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPractice Questions.html
More file actions
348 lines (290 loc) · 9.11 KB
/
Copy pathPractice Questions.html
File metadata and controls
348 lines (290 loc) · 9.11 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
<!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 style="background-color: black; color: white;">
<!-- // *************************************Chnge the text when click on a button******************************* -->
<!-- <div style="text-align: center; align-items: center;padding: 100px;">
<h1>WellCome!</h1>
<button>click Me</button>
</div>-->
<!-- // *************************************Chnge the text when click on a button 2******************************* -->
<style>
.box{
align-items: center;
text-align: center;
padding: 100px;
}
#btn,#bttn {
display: none;
}
#button,.btn, .bttn{
background-color: green;
padding: 10px;
margin: 10px;
border-radius: 5px;
border: none;
color: aliceblue;
cursor: pointer;
}
</style>
<div class="box">
<button id="button">click Me!</button>
<p id="WellCome" ></p>
<button id="btn"></button>
<p id="msg"></p>
<button id="bttn"></button>
</div>
<script>
// // *********************************Plaindrome*************************************
// const palindrome =()=> {
// const str= prompt("Enter a String");
// const reverse = str .split('').reverse('').join('')
// if(str === reverse){
// console.log(`${str}:is Palindrome`);
// }
// else{(str !== reverse)
// console.log(`${str}:is Not Palindrome`);
// }
// };
// palindrome();
// // *************************************Array*******************************
// let arr =[10,20,30,40,50]
// let temp= new Array(arr.length)
// let j=0;
// sum =0;
// let max=arr[0]; //find max number
// let min=arr[0];//Find min number
// for(i=arr.length-1;i>=0;i--){
// temp[j] = arr[i]
// j++;
// sum = sum + arr[i]; //sum of this array
// if(max <arr[i]){
// max = arr[i];
// }
// if(min > arr[i]){
// min = arr[i];
// }
// }
// console.log(arr);
// console.log(temp);
// console.log(sum);
// console.log(max);
// console.log(min);
// ************************************ Online Shopping Discount***********************
// Discount
// const amount=[];
// let sum =0;
// alert('Enter your shooping items ,Enter to fininsh 0:')
// while(true){
// let value = (prompt("Enter you Shopping Amount"))
// if(value === null || Number(value) === 0){
// break;
// }
// amount.push(Number(value))
// }
// for(let i=0; i<amount.length; i++){
// sum =sum+ amount[i]
// }
// console.log(`your amount is ${sum}`);
// const Discount=() =>{
// let discount= 0;
// let finalBill=0;
// if(sum >= 3000){
// discount = sum *15 / 100;}
// else if
// (sum >=2000){
// discount = sum * 10 / 100;
// }
// else if
// (sum >=1500){
// discount = sum * 5 / 100;
// }
// else if
// (sum >=1000){
// discount = sum * 3 / 100;
// }
// else{
// discount =0;
// }
// finalBill = sum - discount ;
// console.log(`your final bill is ${finalBill} with ${discount} rupees discount`);
// }
// Discount();
// ****************** Seat Allocation Coding Problem (Solved By DeepSeek)********************
let cinma = [
[1,0,1,0],
[0,0,1,1],
[0,1,0,1],
[1,0,1,1],
];
let availableCount =0;
for(let row=0; row<4; row++){
for(let seat=0; seat <4; seat++){
if(cinma[row][seat] === 0){
availableCount++;
}
}
}
console.log(`Total Availale seats are ${availableCount}`);
console.log("\nAvailable seats in each column:");
for(let column = 0; column < 4; column++) {
let coulunAvailable = 0;
for (let row=0; row<4; row++ ){
if(cinma[row][column] === 0 ){
coulunAvailable++;
}
}
console.log(`availble coulms are ${column} : ${coulunAvailable}`);
}
console.log("\nAvailable seats in each row:");
for(let row = 0; row < 4; row++) {
let rowAvailable = 0;
for (let col=0; col<4; col++ ){
if(cinma[row][col] === 0 ){
rowAvailable++;
}
}
console.log(`availble row are ${row} : ${rowAvailable}`);
}
// let cinma = [
// [1,0,1,0],
// [0,0,1,1],
// [0,1,0,1],
// [1,0,1,1],
// ];
let availbleSeats = [];
for(let row = 0; row < 4; row++) {
for(let col = 0; col < 4; col++) {
if(cinma[row][col] === 0) {
availbleSeats.push([row, col]); // CORRECT WAY
}
}
}
console.log("Available seat positions:");
console.log(availbleSeats);
// Optional: Nicer display
console.log("\nFormatted list:");
for(let i = 0; i < availbleSeats.length; i++) {
console.log(`Row ${availbleSeats[i][0]}, Seat ${availbleSeats[i][1]}`);
}
// We already have availbleSeats array from before
// availbleSeats = [[0,1], [0,3], [1,0], [1,1], [2,0], [2,2], [3,1]]
// Step 1: Calculate centers
let N = 4; // rows
let M = 4; // seats per row
let centerRow = (N - 1) / 2; // 1.5
let centerSeat = (M - 1) / 2; // 1.5
// Step 2: Initialize tracking
let bestSeat = null;
let bestRowDistance = Infinity; // Very large number
let bestSeatDistance = Infinity;
// Step 3: Loop through available seats
for(let i = 0; i < availbleSeats.length; i++) {
let seat = availbleSeats[i];
let row = seat[0];
let col = seat[1];
// Calculate distances
let rowDist = Math.abs(row - centerRow);
let seatDist = Math.abs(col - centerSeat);
// Compare with current best
// Rule 1: Compare row distance first
if(rowDist < bestRowDistance) {
// This seat is better (closer to center row)
bestSeat = seat;
bestRowDistance = rowDist;
bestSeatDistance = seatDist;
}
else if(rowDist === bestRowDistance) {
// Same row distance, use Rule 2
if(seatDist < bestSeatDistance) {
// This seat is better (closer to center seat)
bestSeat = seat;
bestRowDistance = rowDist;
bestSeatDistance = seatDist;
}
else if(seatDist === bestSeatDistance) {
// Same both distances, use Rule 3
// Compare row numbers (smaller is better)
if(row < bestSeat[0]) {
bestSeat = seat;
bestRowDistance = rowDist;
bestSeatDistance = seatDist;
}
else if(row === bestSeat[0]) {
// Same row, compare seat numbers
if(col < bestSeat[1]) {
bestSeat = seat;
bestRowDistance = rowDist;
bestSeatDistance = seatDist;
}
}
}
}
}
console.log("Best seat is:", bestSeat); // Should be [1, 1]
// *************************************Chnge the text when click on a button******************************* --> -->
// const WellCome= document.querySelector('h1')
// const button = document.querySelector('button')
// button.style.backgroundColor='green'
// button.style.padding='15px'
// button.style.border='green'
// button.style.borderRadius='10px'
// button.style.fontSize='15px'
// button.style.color='white'
// button.style.cursor='pointer'
// button.addEventListener('click' , function(){
// WellCome.innerHTML = "Have a Nice Day"
// })
// *************************************Chnge the text when click on a button 2 ******************************* --> --
// const button=document.getElementById('button')
// const WellCome=document.getElementById('WellCome')
// const btn=document.getElementById('btn')
// const bttn=document.getElementById('bttn')
// // const msg=document.getElementById('msg')
// button.addEventListener('click' , function(){
// WellCome.innerHTML='WellCome';
// WellCome.style.backgroundColor='lightgreen';
// WellCome.style.color='black';
// WellCome.style.borderRadius='10px';
// WellCome.style.padding='15px';
// WellCome.style.margin='10px';
// WellCome.style.fontSize='30px ,bold';
// btn.innerHTML='Thank You!';
// btn.style.display='inline-block';
// btn.style.backgroundColor='green';
// btn.style.padding='10px';
// btn.style.margin='10px';
// btn.style.borderRadius='5px';
// btn.style.border='none';
// btn.style.color='aliceblue';
// btn.style.cursor='pointer';
// })
// btn.addEventListener('click' , function(){
// msg.innerHTML='Have a Nice Day';
// msg.style.backgroundColor='lightgreen';
// msg.style.color='black';
// msg.style.borderRadius='10px';
// msg.style.padding='15px';
// msg.style.margin='10px';
// msg.style.fontSize='30px ,bold';
// bttn.innerHTML='click to reset!';
// bttn.style.backgroundColor='green';
// bttn.style.padding='10px';
// bttn.style.margin='10px';
// bttn.style.borderRadius='5px';
// bttn.style.border='none';
// bttn.style.color='aliceblue';
// bttn.style.cursor='pointer';
// bttn.style.display='inline-block';
// })
// bttn.addEventListener('click' , function(){
// document.body.remove();
// location.reload();
// })
</script>
</body>
</html>