-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript45task.js
More file actions
608 lines (440 loc) · 14.4 KB
/
javascript45task.js
File metadata and controls
608 lines (440 loc) · 14.4 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
console.log("javascript 45 task done By akhlaque channa");
//task no: 02:
let personName = "Akhlaque channa";
console.log(
"Hello " + personName + ", would you like to learn some javascript today ?"
);
// task no: 03:
let userName = "Akhlaque channa";
console.log(userName.toLowerCase);
console.log(userName.toUpperCase);
console.log(userName.split(" ").map((word) => {
return word[0].toUpperCase() + word.slice(1);
})
.join(" "));
// task no : 04:
console.log(
'Nelson Mandela once said, "The greatest glory in living lies not in never falling, but in rising every time we fall."'
);
// task no: 05:
let famous_person = "Nelson Mandela";
let message =
famous_person + ' The greatest glory in living lies not in never falling, but in rising every time we fall.';
console.log(message);
// task no: 06:
let personName1 = " \t akhlaque Channa \n";
console.log(personName1);
console.log(personName1.trim());
// task no: 07:
console.log(6 + 2);
console.log(12 - 4);
console.log(4 * 2);
console.log(64 / 8);
// task no: 08:
console.log(1 + 7);
console.log(14 - 6);
console.log(4 * 2);
console.log(40 / 5);
// task no: 09:
let favoriteNumber = '14'
let message1 = "My favourite number is " + favoriteNumber
console.log(message1);
// task no: 10:
// 1.
let personName2 = "Akhlaque Channa";
console.log(
"Hello " + personName2 + ", would you like to learn some javascript today ?"
);
// 2.
let personNameForSplit = " \t Akhlaque Channa \n";
console.log(personNameForSplit);
console.log(personNameForSplit.trim());
// task no: 11:
let namesFriends = ["Owais hasan", "zuhair", "Kashif khan", "Hamza", "Asif"];
namesFriends.forEach((namesFriends) => {
console.log(namesFriends);
});
// task no: 12:
let namesFriend1 = ["Owais hasan", "zuhair", "Kashif khan", "Hamza", "Asif"];
namesFriend1.forEach(namesFriends1 => {
console.log(`Hy ${namesFriends1}, How are your bro ?`);
})
// task no: 13:
let modeOfsports = ['plane', 'sportscar', 'bike']
let brandOfTransports = ["F-16", "Tesla", "kawasaki"]
for (let i = 0; i < modeOfsports.length; i++) {
console.log("I would love to own " + brandOfTransports[i] + " " + modeOfsports[i] );
}
// task no: 14:
let GuessToInvite = ["Zuhair", "owais", "hamza"];
GuessToInvite.forEach(name => {
console.log(`Hy ${name}, I really love to ask you for a dinner tonight..??`);
})
// task no: 15:
let GuessToInvite1 = ["Zuhair", "owais", "hamza"];
console.log("hamza is not like to dinner with us");
GuessToInvite1[GuessToInvite1.indexOf("hamza")] = "Kashif Khan";
GuessToInvite1.forEach((name) => {
console.log(
`Hy ${name}, I really love to ask you for a dinner tonight..??`
);
});
// task no: 16:
let GuessToInvite2 = ["Zuhair", "owais", "hamza"];
console.log("I decided to make Big dinner party.....");
GuessToInvite2.unshift("Hamza")
GuessToInvite2.push("Naqqash")
GuessToInvite2.splice(GuessToInvite2.length / 2, 0, "Asif")
GuessToInvite2.forEach((name) => {
console.log(
`Hy ${name}, I really love to ask you for a dinner tonight..??`
);
});
// task no: 17:
let GuessToInvite3 = [
"Zuhair",
"owais",
"hamza",
"kashif khan",
"naqqash",
"Asif"
];
console.log(
"Sorry, i can afford only two people for diiner bro"
);
for (let i = GuessToInvite3.length - 1; i >= 2; i--) {
console.log(GuessToInvite3[i] + ", Sorry You are not invited");
GuessToInvite3.pop();
}
GuessToInvite3.map((name) => {
console.log(name + " You are invited");
});
console.log(GuessToInvite3.splice(2));
// task no: 18:
let placeForVisit = ["Naraan", "azad kashmir", "dubai", "makka", "madina"]
let copyOfArray = [...placeForVisit]
console.log(placeForVisit);
console.log(copyOfArray.sort());
console.log(placeForVisit);
console.log(copyOfArray.reverse());
console.log(placeForVisit);
console.log(placeForVisit.reverse());
console.log(placeForVisit.reverse());
console.log(placeForVisit.sort());
console.log(placeForVisit.reverse());
// task no: 19:
let GuessToInvite4 = [
"owais",
"zuhair",
"kashif khan",
"hamza",
"naqqash",
"Asif",
];
console.log("invited " + GuessToInvite4.length + " peoples to dinner.");
// task no: 20:
let countries = []
const addToContry = (...list) => {
countries.push(...list)
}
addToContry("Russia", "dubai", "Japan")
console.log(countries);
// task no: 21:
const carData = new Object()
const addCarData = (array) => {
array.forEach((element, index) => {
carData[index] = element
});
}
addCarData(["Red", "2002", "sedan"])
console.log(carData);
// task no: 22:
let pakProvince = ["Punjab", "Sindh", "Balochistan"];
console.log(pakProvince[5]);
console.log(pakProvince[0]);
// task no: 23:
let firstName = "Akhlaque Channa"
let firstNum = 20
let secondNum = 40
console.log("If firstName == 'Imran'? I Predict True.");
console.log("If firstNum == secondNum? I Predict False.");
console.log("If firstNum > secondNum? I Predict False.");
console.log("If firstNum < secondNum? I Predict True.");
console.log("If firstNum != secondNum? I Predict True.");
console.log("If firstName == 'Akbar'? I Predict False.");
console.log("If firstName == secondNum? I Predict False.");
console.log("If firstNum >= secondNum? I Predict False.");
console.log("If firstNum <= secondNum? I Predict True.");
console.log("If firstNum == 20? I Predict True.");
console.log(firstName == "Akhlaque Channa");
console.log(firstNum == secondNum);
console.log(firstNum > secondNum);
console.log(firstNum < secondNum);
console.log(firstNum != secondNum);
console.log(firstName == "Hanif Channa");
console.log(firstName == secondNum);
console.log(firstNum >= secondNum);
console.log(firstNum <= secondNum);
console.log(firstNum == 20);
// task no: 24:
console.log('If "Akhlaque" == "Akhlaque"? I predict True');
console.log("Akhlaque" == "Akhlaque");
console.log('If "Akhlaque" == "hanif"? I predict false');
console.log("Akhlaque" == "hanif");
console.log('If 5 == 9? I predict false');
console.log(5 == 9);
console.log('If 143 == 143? I predict True');
console.log(143 == 143);
console.log('If 14 > 32? I predict false');
console.log(14 > 32);
console.log('If 18 < 46? I predict True');
console.log(18 < 46);
console.log('If 3 >= 80? I predict false');
console.log(3 >= 80);
console.log('If 89 <= 120? I predict True');
console.log(89 <= 120);
console.log('If 55 <= 55? I predict True');
console.log(55 <= 55);
console.log('If "Hamza" == "Hamza" && 90 > 12? I predict True');
console.log("Hamza" == "Hamza" && 90 > 12);
console.log('If "Hamza" == "Hamza" && 90 < 12? I predict False');
console.log("Hamza" == "Hamza" && 90 < 12);
console.log('If "Hamza" == "zuhair" || 90 > 12? I predict True');
console.log("Hamza" == "zuhair" || 90 > 12);
console.log('If "Hamza" == "zuhair" || 90 < 12? I predict False');
console.log("Hamza" == "zuhair" || 90 < 12);
console.log('If [88, 90, 12].includes(12)? I predict True');
console.log([88, 90, 12].includes(12));
console.log('If [88, 90, 12].includes(65)? I predict False');
console.log([88, 90, 12].includes(65));
// task no: 25:
let alienColor = "Red";
if (alienColor == "Red") {
console.log("You just earned 5 points");
}
if (alienColor != "Red") {
console.log("failed");
}
// task no: 26:
let alienColor1 = "green";
if (alienColor1 == "green") {
console.log("You just earned 5 points");
} else {
console.log("You just earned 10 points");
}
// task no: 27:
let alienColor2 = "green";
if (alienColor2 == "green") {
console.log("You just earned 5 points");
} else if (alienColor2 == "yellow") {
console.log("You just earned 10 points");
} else if (alienColor2 == "red") {
console.log("You just earned 15 points");
}
alienColor3 = "red";
if (alienColor3 == "green") {
console.log("You just earned 5 points");
} else if (alienColor3 == "yellow") {
console.log("You just earned 10 points");
} else if (alienColor3 == "red") {
console.log("You just earned 15 points");
}
alienColor4 = "yellow";
if (alienColor4 == "green") {
console.log("You just earned 5 points");
} else if (alienColor4 == "yellow") {
console.log("You just earned 10 points");
} else if (alienColor4 == "red") {
console.log("You just earned 15 points");
}
// task no: 28:
let age = 18;
if (age < 2) {
console.log("The person age is a baby");
} else if (age >= 2 && age < 4) {
console.log("The person age is a Toddler");
} else if (age >= 4 && age < 13) {
console.log("The person age is a kid");
} else if (age >= 13 && age < 20) {
console.log("The person age is a teenager");
} else if (age >= 20 && age < 65) {
console.log("The person age is a adult");
} else if (age >= 65) {
console.log("The person age is a elder");
}
// task no: 29:
let favoriteFruitsList = ["mango", "apple", "Oranges"];
if (favoriteFruitsList.includes("mango")) {
console.log("I really like mangoes");
}
if (favoriteFruitsList.includes("apple")) {
console.log("I really like apples");
}
if (favoriteFruitsList.includes("Oranges")) {
console.log("I really like Oranges");
}
if (favoriteFruitsList.includes("strawberry")) {
console.log("I really like strawberries");
}
if (favoriteFruitsList.includes("Pineapple")) {
console.log("I really like Pineapple");
}
// task no: 30:
let usernames5 = ["admin", "leader", "user", "customer", "online"];
usernames5.map((name1) => {
if (name1 == "admin") {
console.log("Hello admin, would you like to see a status report?");
} else {
console.log(`Hello ${name1}, thank you for logging in again`);
}
});
// task no: 31:
let username = ['user1', 'luser2', 'user3']
if (username.length == 0) {
console.log("We need to find some users");
}
username = []
if (username.length == 0) {
console.log("We need to find some users");
}
// task no: 32:
let currentUsers = ["admin", "leader", "user", "customer", "online"];
let newUsers = ["Leader", "soldier", "king", "online", "servant"];
newUsers.map((user) => {
if (currentUsers.includes(user.toLowerCase())) {
console.log(user + ", username is not available please choose another");
} else {
console.log(user + ", username is available");
}
});
// task no: 33:
let toOrdiNumbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
toOrdiNumbers.map((num) => {
if (num == 1) {
console.log("1st");
} else if (num == 2) {
console.log("2nd");
} else if (num == 3) {
console.log("3rd");
} else {
console.log(num + "th");
}
});
// task no: 34:
let pizzaNameList = ['perimax',"fajitamax","behari boti"]
for (const pizza of pizzaNameList) {
console.log("I like " + pizza + " pizza");
}
console.log("I really like " + pizzaNameList[0] + " pizza");
console.log("I mostly like " + pizzaNameList[2] + " pizza");
console.log("I sometimes like " + pizzaNameList[3] + " pizza");
// task no: 35:
let animals = ["cat", "dog", "cheetah"];
for (const animal of animals) {
console.log("A " + animals + " would make a great pet");
}
console.log("Cat has four legs");
console.log("Dog has four legs");
console.log("parrot has four legs");
// task no: 36:
const makeShirt = (size, message) => {
console.log("The shirt size is " + size + " an the message to print on is " + message);
}
makeShirt(44, "Akhlaque Channa")
// task no: 37:
const makeShirt1 = (size = "large", message = "I love Javascript") => {
if (size == "large" || size == "medium") {
console.log(
"The shirt size is " + size + " and the message to print on is " + message
);
} else {
console.log(
"The shirt size is " + size + " and the message to print on is " + message
);
}
};
makeShirt1();
makeShirt1("medium");
makeShirt1("small", "Check My Worth");
// task no: 38:
function CitiesName(name, countryName = "Pakistan") {
console.log(name + " is in " + countryName);
}
CitiesName("karachi");
CitiesName("lahore");
CitiesName("Quetta");
// task no: 39:
function cityCountry1(cityName, countryName) {
console.log(`"${cityName}, ${countryName}"`);
}
cityCountry1("Islamabad", "Pakistan");
// task no: 40:
const makeAlbum = (artistName, albumTitle, numOfTracks = 0) => {
return {
'Artist Name': artistName,
'Album Title': albumTitle,
'Number Of Tracks': numOfTracks
}
}
console.log(makeAlbum('Shehzad Roy', 'kangna', 5));
console.log(makeAlbum('Shehzad Roy', 'yaad', 7));
console.log(makeAlbum('Shehzad Roy', 'Aag', 10));
console.log(makeAlbum('Shehzad Roy', 'Teri soorat', 5));
// task no: 41:
let magicians = ["akhlaque", "owais", "hamza"];
const showMagicians = (array) => {
array.map((name) => {
console.log(name);
});
};
showMagicians(magicians);
// task no: 42:
let magicians1 = ["akhlaque", "owais", "hamza"];
const makeGreat = (array) => {
array.map((name) => {
magicians1[magicians1.indexOf(name)] = "Great " + name;
});
console.log(array);
};
makeGreat(magicians1);
// task no: 43:
let magicians3 = ["akhlaque", "owais", "hamza"];
let magiciansCopy = [...magicians3];
const showMagicians1 = (array) => {
array.map((name) => {
console.log(name);
});
};
const makeGreat1 = (array) => {
array.map((name) => {
array[array.indexOf(name)] = "Great " + name;
});
return array;
};
let newArray = makeGreat1(magiciansCopy);
showMagicians1(magicians3);
showMagicians1(newArray);
// task no: 44:
function itemsOnSandwich(array) {
console.log(
"The person demond items on the sandwich: "
);
array.map((item, index) => {
console.log(`${index}) ${item}`);
});
}
itemsOnSandwich(["Tomatoes", "Ketchup"]);
itemsOnSandwich(["Tomatoes", "Mayonese", "Carrot"]);
itemsOnSandwich(["Tomatoes", "Ketchup", "Cucumber", "Maynoese"]);
// task no: 45:
const carInformation = (manufacturer, model, ...information) => {
let lastObject = Object.assign(information[0], information[1]);
return {
Manufacturer: manufacturer,
"Model Number": model,
...lastObject,
};
};
console.log(
carInformation("BMW", "Model X", { Color: "Red" }, { Rims: "Steel" })
);