-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
369 lines (308 loc) · 12.7 KB
/
app.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
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
document.write("<br>");
document.write("<h3>Question no 01 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques1() ">Click Me</button>');
document.write("<br>");
document.write("<br>");
function ques1() {
var resultDiv = document.getElementById("pere");
resultDiv.innerHTML = 'var studentNamesLiteral = [];<br><br>';
}
document.write('<div id="pere"></div>')
// question no 2
document.write("<h3>Question no 02 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques2();">Click Me</button>');
function ques2() {
var resultDiv = document.getElementById("pe");
resultDiv.innerHTML = '<br>var studentNamesObject = new Array();<br>';
}
document.write('<div id="pe"></div>')
document.write("<br>");
document.write("<br>");
//question no 3
document.write("<h3>Question no 03 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques3()">Click Me</button>');
function ques3() {
var resultDiv = document.getElementById("per");
resultDiv.innerHTML = '<br>var stringsArray = ["apple", "banana", "orange"];<br>';
}
document.write('<div id="per"></div>')
document.write("<br>");
document.write("<br>");
//question no 4
document.write("<h3>Question no 04 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques4()">Click Me</button>');
function ques4() {
var resultDiv = document.getElementById("perra");
resultDiv.innerHTML = '<br>var numbersArray = [1, 2, 3, 4, 5]; <br>';
};
document.write('<div id="perra"></div>')
document.write("<br>");
document.write("<br>");
//question no 5
document.write("<h3>Question no 05 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques5()">Click Me</button>');
function ques5() {
var resultDiv = document.getElementById("perer");
resultDiv.innerHTML = '<br>var booleanArray = [true, false, true, true]; <br>';
}
document.write('<div id="perer"></div>')
document.write("<br>");
document.write("<br>");
//question no 6
document.write("<h3>Question no 06 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques6()"">Click Me</button>');
function ques6() {
var resultDiv = document.getElementById("pererl");
resultDiv.innerHTML = '<br>var mixedArray = ["apple", 5, true, "banana", 10];<br>';
}
document.write('<div id="pererl"></div>')
document.write("<br>");
document.write("<br>");
//question no 7
document.write("<h3>Question no 07 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques7()">Click Me</button>');
function ques7() {
let qualifications = ["SSC", "HSC", "BCS", "BS", "BCOM", "MS", "M. Phil.", "PhD"];
let qualificationsList = document.getElementById("qualificationsList");
qualifications.forEach(qualification => {
let listItem = document.createElement("li");
listItem.textContent = qualification;
qualificationsList.appendChild(listItem);
});
}
document.write('<br><br><div id="qualificationsList"></div>')
document.write("<br>");
document.write("<br>");
//question no 8
document.write("<h3>Question no 08 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques8()">Click Me</button>');
function ques8() {
var nameone = prompt('first name ');
var nametwo = prompt('second name ');
var namethree = prompt('thired name');
let studentNames = [nameone, nametwo, namethree];
var Scorone = prompt('first Score \rAssuming scores out of 500 for each student ');
var Scortwo = prompt('Second Score \r Assuming scores out of 500 for each student ');
var Scorthree = prompt('thired Score\r Assuming scores out of 500 for each student');
let scores = [Scorone, Scortwo, Scorthree];
for (let i = 0; i < studentNames.length; i++) {
let percentage = (scores[i] / 500) * 100;
console.log(studentNames[i] + ": Score - " + scores[i] + ", Percentage - " + percentage + "%");
alert(studentNames[i] + ": Score - " + scores[i] + ", Percentage - " + percentage + "%");
}
}
document.write("<br>");
document.write("<br>");
//question no 9
document.write("<h3>Question no 09 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques9()">Click Me</button>');
function ques9() {
// Initialize an array with color names
var colorArray = ['Red', 'Green', 'Blue', 'Yellow', 'Orange'];
// Display the original array
console.log('Original array of colors:' + colorArray);
// console.log(colorArray);
// Ask the user for a color to add to the beginning
var colorToAddAtBeginning = prompt('Enter a color to add to the beginning:');
colorArray.unshift(colorToAddAtBeginning);
// Display the updated array after adding at the beginning
console.log('Updated array after adding at the beginning:' + colorArray);
alert('Updated array after adding at the beginning:' + colorArray);
// console.log(colorArray);
// Ask the user for a color to add to the end
var colorToAddAtEnd = prompt('Enter a color to add to the end:');
colorArray.push(colorToAddAtEnd);
// Display the updated array after adding at the end
console.log('Updated array after adding at the end:' + colorArray);
alert('Updated array after adding at the end:' + colorArray);
// console.log(colorArray);
// Add two more colors to the beginning
colorArray.unshift('Purple', 'Pink');
// Display the updated array after adding two colors at the beginning
console.log('Updated array after adding two colors at the beginning:' + colorArray);
alert('Updated array after adding two colors at the beginning:' + colorArray);
// console.log(colorArray);
// Delete the first color in the array
colorArray.shift();
// Display the updated array after deleting the first color
console.log('Updated array after deleting the first color:' + colorArray);
alert('Updated array after deleting the first color:' + colorArray);
// console.log(colorArray);
// Delete the last color in the array
colorArray.pop();
// Display the updated array after deleting the last color
console.log('Updated array after deleting the last color:' + colorArray);
alert('Updated array after deleting the last color:' + colorArray);
// console.log(colorArray);
// Ask the user for an index and a color to add
var indexToAdd = parseInt(prompt('Enter the index to add a color:'));
var colorToAddAtIndex = prompt('Enter the color to add at the specified index:');
colorArray.splice(indexToAdd, 0, colorToAddAtIndex);
// Display the updated array after adding at the specified index
console.log('Updated array after adding at the specified index:' + colorArray);
alert('Updated array after adding at the specified index:' + colorArray);
// console.log(colorArray);
// Ask the user for an index and the number of colors to delete
var indexToDelete = parseInt(prompt('Enter the index to delete color(s):'));
var numColorsToDelete = parseInt(prompt('Enter the number of colors to delete:'));
colorArray.splice(indexToDelete, numColorsToDelete);
// Display the updated array after deleting colors at the specified index
console.log('Updated array after deleting colors at the specified index:' + colorArray);
alert('Updated array after deleting colors at the specified index:' + colorArray);
// console.log(colorArray);
}
document.write("<br>");
document.write("<br>");
//question no 10
document.write("<h3>Question no 10 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques10()">Click Me</button>');
function ques10() {
alert('the Score in ascending order using Array’s sort method.')
var scoronest = parseInt(prompt('put the score of student one! '))
var scortwost = parseInt(prompt('put the score of student two! '))
var scorthreest = parseInt(prompt('put the score of student three! '))
var scorfourst = parseInt(prompt('put the score of student four! '))
var scorfivest = parseInt(prompt('put the score of student five! '))
let studentScoes = [scoronest, scortwost, scorthreest, scorfourst, scorfivest];
studentScoes.sort(function (a, b) { return a - b });
console.log("Sorted student scores in ascending order:", studentScoes);
alert("Sorted student scores in ascending order:\r" + studentScoes);
}
document.write("<br>");
document.write("<br>");
//question no 11
document.write("<h3>Question no 11 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques11()">Click Me</button>');
function ques11() {
// Initialize array with city names
let cities = ["New York", "London", "Tokyo", "Paris", "Sydney"];
alert(cities)
// Initialize selectedCities array
let selectedCities = [];
// Copy three elements from cities array to selectedCities array
selectedCities = cities.slice(0, 3);
// Display the selectedCities array
console.log("Selected cities:", selectedCities);
alert("Selected cities:" + selectedCities);
}
document.write("<br>");
document.write("<br>");
//question no 12
document.write("<h3>Question no 12 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques12()">Click Me</button>');
function ques12() {
var arr = ["This", "is", "my", "cat"];
var singleString = arr.join(" ");
console.log(singleString);
alert(singleString);
}
document.write("<br>");
document.write("<br>");
//question no 13
document.write("<h3>Question no 13 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques13()">Click Me</button>');
function ques13() {
var fifoArray = [];
fifoArray.unshift("mouse");
fifoArray.unshift("keyboard");
fifoArray.unshift("printer");
var firstValue = fifoArray.shift();
var secondValue = fifoArray.shift();
var thirdValue = fifoArray.shift();
console.log("First value:", firstValue);
alert("First value:", firstValue);
console.log("Second value:", secondValue);
alert("Second value:", secondValue);
console.log("Third value:", thirdValue);
alert("Third value:", thirdValue);
}
document.write("<br>");
document.write("<br>");
//question no 14
document.write("<h3>Question no 14 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques14()">Click Me</button>');
function ques14() {
// Initialize an empty arra
let lifoArray = [];
lifoArray.push("mouse");
lifoArray.push("keyboard");
lifoArray.push("printer");
let lastValue = lifoArray.pop();
let secondLastValue = lifoArray.pop();
let thirdLastValue = lifoArray.pop();
console.log("Last value:", lastValue);
alert("Last value:", lastValue);
console.log("Second last value:", secondLastValue);
alert("Second last value:", secondLastValue);
console.log("Third last value:", thirdLastValue);
alert("Third last value:", thirdLastValue);
}
document.write("<br>");
document.write("<br>");
//question no 15
document.write("<h3>Question no 15 :-</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="ques15()">Click Me</button>');
function ques15() {
let manufacturers = ["Apple", "Samsung", "Motorola", "Nokia", "Sony", "Haier"];
// Start building the select menu
let selectMenu = "<select id='manufacturerSelect'>";
// Add options for each manufacturer
for (let i = 0; i < manufacturers.length; i++) {
selectMenu += "<option value='" + manufacturers[i] + "'>" + manufacturers[i] + "</option>";
}
// Close the select menu tag
selectMenu += "</select>";
// Display the select menu in the browser
// document.write(selectMenu);
var resultDiv = document.getElementById("caat");
resultDiv.innerHTML = '<br>' + selectMenu;
}
document.write('<div id="caat"></div>')
document.write("<br>");
document.write("<br>");
document.write('<div style="color: blue;background-color: black;"><br><h1>Best OF luck<span style="font-size:50px;">👋</span></h1><br></div>')//👋