-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
348 lines (314 loc) · 11.2 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
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="checkCharacterType() ">Click Me</button>');
document.write("<br>");
document.write("<br>");
function checkCharacterType(character) {
let cityName = prompt("Enter the name of the city:");
if (cityName.toLowerCase() === "karachi") {
console.log("Welcome to the city of lights!");
alert("Welcome to the city of lights!");
} else if (cityName.toLowerCase() === "lahore") {
console.log("the capital of the Pakistani province of Punjab and the second largest city in the country!");
alert("the capital of the Pakistani province of Punjab and the second largest city in the country!");
} else {
console.log("Welcome to " + cityName + "!");
alert("Welcome to " + cityName + "!");
}
}
document.write("<h3>Question no 02</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="displayLarger();">Click Me</button>');
function displayLarger() {
var gender = prompt("Enter the Gender :");
if (gender.toLowerCase() === 'male') {
alert('Good Morning Sir!');
console.log('Good Morning Sir!');
} else if (gender.toLowerCase() === 'female') {
alert('Good Morning Ma’am!');
console.log('Good Morning Ma’am!');
} else {
alert('this is no gender')
console.log('this is no gender')
}
}
document.write("<br>");
document.write("<br>");
document.write("<h3>Question no 03</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="moiza()">Click Me</button>');
// Prompt the user to enter a number
function moiza() {
//color of road traffic signal
var signal = prompt("Enter the color of road traffic signal:");
if (signal.toLowerCase() === 'red') {
alert('Must Stop!');
console.log('Must Stop!');
} else if (signal.toLowerCase() === 'yellow') {
alert('Ready to move!');
console.log('Ready to move!');
} else if (signal.toLowerCase() === 'green') {//Move now
alert('Move now!');
console.log('Move now!');
} else {
alert('this is no colour')
console.log('this is no colour')
}
}
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() {
let remainingFuel = parseFloat(prompt("Enter the remaining fuel in your car (in liters):"));
// Checking if the remaining fuel is less than 0.25 liters
if (remainingFuel < 0.25) {
console.log("Please refill the fuel in your car.");
alert("Please refill the fuel in your car.");
} else {
console.log("Your fuel level is sufficient.");
alert("Your fuel level is sufficient.");
}
};
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() {
// Script
var a = 4;
if (++a === 5) {
console.log("a. given condition for variable a is true");
}
var b = 82;
if (b++ === 83) {
console.log("b. given condition for variable b is true");
}
var c = 12;
if (c++ === 13) {
console.log("c. condition 1 is true");
}
if (c === 13) {
console.log("c. condition 2 is true");
}
if (++c < 14) {
console.log("c. condition 3 is true");
}
if (c === 14) {
console.log("c. condition 4 is true");
}
var materialCost = 20000;
var laborCost = 2000;
var totalCost = materialCost + laborCost;
if (totalCost === laborCost + materialCost) {
console.log("d. The cost equals");
}
if (true) {
console.log("e. True");
}
if (false) {
console.log("e. False");
}
if ("car" < "cat") {
console.log("f. car is smaller than cat");
}
var per = document.getElementById("pere");
per.innerHTML = '<br> <ol><li>a. given condition for variable a is true</li><li>c. condition 2 is true</li><li>c. condition 4 is true</li><li>d. The cost equals</li><li>e. True</li><li>f. car is smaller than cat</li></ol><br>';
}
document.write('<div id="pere"></div>')
document.write("<br>");
document.write("<br>");
//question no 6
document.write("<h3>Question no 06</h3>");
document.write("<br>");
document.write("<h3>Generator MarkSheet</h3>");
document.write("<br>");
document.write("<h4>Result :</h4>");
document.write("<br>");
document.write('<button id="btn" onclick="calculateGrade()"">Click Me</button>');
function calculateGrade() {
// Get input values from user using prompts
var subject1Marks = parseFloat(prompt("Enter marks obtained in subject 1:"));
var subject2Marks = parseFloat(prompt("Enter marks obtained in subject 2:"));
var subject3Marks = parseFloat(prompt("Enter marks obtained in subject 3:"));
var totalMarks = parseFloat(prompt("Enter total marks:"));
// Calculate percentage
var totalObtainedMarks = subject1Marks + subject2Marks + subject3Marks;
var percentage = (totalObtainedMarks / totalMarks) * 100;
// Calculate grade
var grade;
if (percentage >= 90) {
grade = 'A+';
} else if (percentage >= 80) {
grade = 'A-One';
} else if (percentage >= 70) {
grade = 'A';
} else if (percentage >= 60) {
grade = 'B';
} else if (percentage >= 50) {
grade = 'c';
} else if (percentage >= 40) {
grade = 'D';
} else {
grade = 'Fail';
}
//Remarks
var Remarks;
if (percentage >= 90) {
Remarks = 'Wonderful';
} else if (percentage >= 80) {
Remarks = 'Excellent';
} else if (percentage >= 70) {
Remarks = 'Very Good';
} else if (percentage >= 60) {
Remarks = 'Good';
} else if (percentage >= 50) {
Remarks = 'Fair';
} else if (percentage >= 40) {
Remarks = 'Bad';
} else {
Remarks = 'You Need To Improve';
}
// Display result
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = '<br><h4>MarkSheet</h4><br>' + "Percentage: " + percentage.toFixed(2) + "%<br>Grade: " + grade + '<br>Total Marks :' + totalMarks + '<br>Obtain Marks :' + totalObtainedMarks + '<br>Remarks :' + Remarks;
}
document.write('<div id="result"></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() {
var secretNumber = Math.floor(Math.random() * 10) + 1;
var userGuess = parseInt(prompt("Guess the secret number (between 1 and 10):"));
if (userGuess === secretNumber) {
console.log("Bingo! Correct answer");
alert("Bingo! Correct answer");
} else if (userGuess + 1 === secretNumber || userGuess - 1 === secretNumber) {
console.log("Close enough to the correct answer");
alert("Close enough to the correct answer");
} else {
console.log("Sorry, incorrect guess. The secret number was " + secretNumber);
alert("Sorry, incorrect guess. The secret number was " + secretNumber);
}
}
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 number = parseInt(prompt("Enter a number:"));
if (number % 3 === 0) {
console.log(number + " is divisible by 3.");
alert(number + " is divisible by 3.");
} else {
console.log(number + " is not divisible by 3.");
alert(number + " is not divisible by 3.");
}
}
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() {
var oddeven = parseInt(prompt("Enter a number:"));
if (oddeven % 2 === 0) {
console.log(oddeven + " is an even number.");
alert(oddeven + " is an even number.");
} else {
console.log(oddeven + " is an odd number.");
alert(oddeven + " is an odd number.");
}
}
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() {
var tempratu = parseInt(prompt("Enter a wether temprature"));
if (tempratu >= 40) {
console.log('It is too hot outside!');
alert('It is too hot outside!');
} else if (tempratu >= 30) {
console.log('The Weather today is Normal!');
alert('The Weather today is Normal!');
} else if (tempratu >= 20) {
console.log('Today’s Weather is cool!');
alert('Today’s Weather is cool!');
} else if (tempratu >= 10) {
console.log('OMG! Today’s weather is so Cool!');
alert('OMG! Today’s weather is so Cool!');
} else if (tempratu >= 50) {
onsole.log('Tempratureis very high! ');
alert('Temprature is very high!');
} else {
console.log('Please Put the Temprature! ');
alert(' Please Put the Temprature!');
}
}
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() {
var firstnum = parseInt(prompt("Enter a first number:"));
var secondnum = parseInt(prompt("Enter a second number:"));
var thirednum = prompt("Enter a Operation (+, -, *, /, %):");
if (thirednum === "+") {
console.log(firstnum + secondnum);
alert(firstnum + secondnum);
} else if (thirednum === "-") {
console.log(firstnum - secondnum);
alert(firstnum - secondnum);
} else if (thirednum === "/") {
console.log(firstnum / secondnum);
alert(firstnum / secondnum);
} else if (thirednum === "*") {
console.log(firstnum * secondnum);
alert(firstnum * secondnum);
} else if (thirednum === "%") {
console.log(firstnum % secondnum);
alert(firstnum % secondnum);
} else {
console.log(oddeven + " is an odd number.");
alert(oddeven + " is an odd number.");
}
}
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>')//👋