Skip to content

Commit 50d27f9

Browse files
JavaScript Tasks
0 parents  commit 50d27f9

File tree

11 files changed

+487
-0
lines changed

11 files changed

+487
-0
lines changed

Task1.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Javascript Task1</title>
8+
<link rel="stylesheet" href="style.css">
9+
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon">
10+
</head>
11+
12+
<body>
13+
<div class="container">
14+
<a href="index.html"><button>Home</button></a>
15+
<a href="#"><button>Task 1</button></a>
16+
<a href="Task2.html"><button>Task 2</button></a>
17+
<a href="Task3.html"><button>Task 3</button></a>
18+
<a href="Task4.html"><button>Task 4</button></a>
19+
</div>
20+
21+
<script src="Task1.js"></script>
22+
</body>
23+
24+
</html>

Task1.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
let number = 10
2+
document.write('<font size=5> Result: <br> The value of a is:' + ' ' + number + '<br> .................................................... <br> <br> ')
3+
4+
document.write('The value of ++a is:' + ' ' + ++number, '<br>')
5+
document.write('Now the value of a is:' + ' ' + number, '<br> <br> ')
6+
7+
document.write('The value of a++ is:' + ' ' + number++, '<br>')
8+
document.write('Now the value of a is:' + ' ' + number, '<br> <br> ')
9+
10+
document.write('The value of --a is:' + ' ' + --number, '<br>')
11+
document.write('Now the value of a is:' + ' ' + number, '<br> <br> ')
12+
13+
document.write('The value of a-- is:' + ' ' + number--, '<br>')
14+
document.write('Now the value of a is:' + ' ' + number, '<br> <br> ')
15+
16+
var a = 2, b = 1;
17+
// 1 - 0 = 1 + 1 = 2 + 1 = 3
18+
// a = a + b = 2 + b = 4
19+
var result = --a - --b + ++b + b--;
20+
21+
document.write('a is' + ' ' + 1, '<br>')
22+
document.write('b is' + ' ' + 1, '<br>')
23+
document.write('The result is:' + ' ' + result, '<br> <br>')
24+
25+
let userName = prompt('Enter your name')
26+
alert('Welcome to' + ' ' + userName)
27+
28+
let table = prompt('Enter any number')
29+
30+
if (table == '') {
31+
document.write('Table of' + ' ' + 5 + '<br> <br>')
32+
}
33+
else {
34+
document.write('Table of' + ' ' + table + '<br> <br>')
35+
}
36+
37+
for (i = 1; i <= 10; i++) {
38+
if (table == '') {
39+
document.write(5 + ' ' + 'x' + ' ' + i + ' ' + '=' + ' ' + 5 * i, '<br>')
40+
} else {
41+
document.write(table + ' ' + 'x' + ' ' + i + ' ' + '=' + ' ' + table * i, '<br>')
42+
}
43+
44+
}
45+
46+
let subject1 = prompt('Enter your first subject name')
47+
let subject2 = prompt('Enter your second subject name')
48+
let subject3 = prompt('Enter your third subject name')
49+
50+
let totalMarks_forEachSubject = 100
51+
52+
let subject1_obtainedMarks = +prompt('Enter your obtained marks for' + ' ' + subject1)
53+
let subject2_obtainedMarks = +prompt('Enter your obtained marks for' + ' ' + subject2)
54+
let subject3_obtainedMarks = +prompt('Enter your obtained marks for' + ' ' + subject3)
55+
56+
let totalMarks_obtainedMarks = subject1_obtainedMarks + subject2_obtainedMarks + subject3_obtainedMarks
57+
58+
let percentage_ofSubject1 = subject1_obtainedMarks / totalMarks_forEachSubject * 100
59+
let percentage_ofSubject2 = subject2_obtainedMarks / totalMarks_forEachSubject * 100
60+
let percentage_ofSubject3 = subject3_obtainedMarks / totalMarks_forEachSubject * 100
61+
62+
let totalPercentage = (subject1_obtainedMarks + subject2_obtainedMarks + subject3_obtainedMarks) / 300 * 100
63+
64+
document.write('Subject &nbsp &nbsp Total Marks &nbsp &nbsp Obtained Marks &nbsp &nbsp Percentage <br>')
65+
66+
document.write(subject1 + '&nbsp &nbsp &nbsp &nbsp' + totalMarks_forEachSubject + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + subject1_obtainedMarks + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + percentage_ofSubject1 + ' %', '<br>')
67+
document.write(subject2 + '&nbsp &nbsp &nbsp &nbsp' + totalMarks_forEachSubject + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + subject2_obtainedMarks + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + percentage_ofSubject2 + ' %', '<br>')
68+
document.write(subject3 + '&nbsp &nbsp &nbsp &nbsp' + totalMarks_forEachSubject + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + subject3_obtainedMarks + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + percentage_ofSubject3 + ' %', '<br>')
69+
70+
document.write('&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + 100 + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + totalMarks_obtainedMarks + '&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp' + totalPercentage + ' %')

Task2.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Javascript Task2</title>
8+
<link rel="stylesheet" href="style.css">
9+
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon">
10+
</head>
11+
12+
<body>
13+
<div class="container">
14+
<a href="index.html"><button>Home</button></a>
15+
<a href="Task1.html"><button>Task 1</button></a>
16+
<a href="#"><button>Task 2</button></a>
17+
<a href="Task3.html"><button>Task 3</button></a>
18+
<a href="Task4.html"><button>Task 4</button></a>
19+
</div>
20+
21+
<script src="Task2.js"></script>
22+
</body>
23+
24+
</html>

Task2.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
function checkCharacterType(char) {
2+
3+
let asciiCode = char.charCodeAt(0);
4+
5+
if (asciiCode >= 48 && asciiCode <= 57) {
6+
return "The character is a number.";
7+
}
8+
else if (asciiCode >= 65 && asciiCode <= 90) {
9+
return "The character is an uppercase letter.";
10+
}
11+
else if (asciiCode >= 97 && asciiCode <= 122) {
12+
return "The character is a lowercase letter.";
13+
} else {
14+
return "The character is not a number, uppercase letter, or lowercase letter.";
15+
}
16+
}
17+
18+
let inputChar = prompt("Enter a character:");
19+
20+
if (inputChar.length !== 1) {
21+
console.log("Please enter a single character.");
22+
} else {
23+
let result = checkCharacterType(inputChar);
24+
alert(result);
25+
}
26+
27+
let integer1 = +prompt('Enter your first integer')
28+
let integer2 = +prompt('Enter your second integer')
29+
30+
if (integer1 > integer2) {
31+
alert('integer1 ' + 'is greater than ' + 'integer2')
32+
}
33+
else if (integer1 < integer2) {
34+
alert('Integer1 ' + 'is lesser than ' + 'integer2')
35+
} else {
36+
alert('Both are equals')
37+
}
38+
39+
let number1 = prompt('Enter any number \n i will tell you whether it is positive or negative')
40+
41+
if (number1 < 0) {
42+
alert('it is negative')
43+
}
44+
else if (number1 > 0) {
45+
alert('it is positive')
46+
}
47+
else {
48+
alert('íts zero')
49+
}
50+
51+
let character = prompt('Enter any character (i.e. string of length 1)')
52+
let vowel = ['a', 'e', 'i', 'o', 'u']
53+
54+
let flag = 'no'
55+
56+
for (i = 0; i < vowel.length; i++) {
57+
if (vowel[i] == character) {
58+
flag = 'yes'
59+
break
60+
}
61+
}
62+
if (flag == 'yes') {
63+
alert(true)
64+
}
65+
else {
66+
alert(false)
67+
}
68+
69+
70+
71+
72+
73+
let correct_password = '123456'
74+
75+
let password = prompt('Enter the following password : ' + correct_password)
76+
if (password == '') {
77+
alert('Please enter your password')
78+
}
79+
else if (password == correct_password) {
80+
alert('“Correct! The password you entered matches the original password”')
81+
}
82+
else {
83+
alert('Incorrect password')
84+
}
85+
86+
var greeting;
87+
var hour = 13;
88+
if (hour < 18) {
89+
greeting = "Good day";
90+
}
91+
else {
92+
greeting = "Good evening";
93+
}
94+
console.log(greeting + '<br> <br>');
95+
96+
let time = prompt('Enter time in your clock in 24 hours format like : 2200')
97+
98+
if (time >= '0000' && time < 1200) {
99+
alert('Good Morning!')
100+
}
101+
else if (time >= 1200 && time < 1700) {
102+
alert('Good afternoon!')
103+
}
104+
else if (time >= 1700 && time < 2100) {
105+
alert('Good evening!')
106+
}
107+
else if (time >= 2100 && time <= 2359) {
108+
alert('Good night!')
109+
}
110+
else {
111+
alert('Please enter time in your clock in 24 hours')
112+
}

Task3.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Javascript Task3</title>
8+
<link rel="stylesheet" href="style.css">
9+
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon">
10+
</head>
11+
12+
<body>
13+
<div class="container">
14+
<a href="index.html"><button>Home</button></a>
15+
<a href="Task1.html"><button>Task 1</button></a>
16+
<a href="Task2.html"><button>Task 2</button></a>
17+
<a href="#"><button>Task 3</button></a>
18+
<a href="Task4.html"><button>Task 4</button></a>
19+
</div>
20+
21+
<script src="Task3.js"></script>
22+
</body>
23+
24+
</html>

Task3.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
let studentNames = []
2+
let students = new Array()
3+
4+
let string_array = ['mudassir', 'hadi']
5+
let number_array = [10, 20]
6+
let boolean_array = [true, false]
7+
let mixed_array = ['mudassir', 20, true]
8+
9+
let qualifications = [' 1) SSC <br>' + '2) HSC <br>' + '3) BCS <br>' + '4) BS <br>' + '5) BCOM <br>' + '6) MS <br>' + '7) M. Phil. <br>' + '8) PhD <br>']
10+
document.write('<font size=5> Qualifications: <br> <br>' + qualifications + '<br> <br>')
11+
12+
let students_Names = ['Michael', 'John', 'Tony']
13+
let students_scores = [320, 230, 480]
14+
15+
document.write('Score of ' + students_Names[0] + ' ' + 'is ' + students_scores[0] + '.' + 'Percentage is ' + students_scores[0] / 500 * 100 + '% <br>')
16+
document.write('Score of ' + students_Names[1] + ' ' + 'is ' + students_scores[1] + '.' + 'Percentage is ' + students_scores[1] / 500 * 100 + '% <br>')
17+
document.write('Score of ' + students_Names[2] + ' ' + 'is ' + students_scores[2] + '.' + 'Percentage is ' + students_scores[2] / 500 * 100 + '% <br> <br>')
18+
19+
let color = ['red', 'green']
20+
let color_asking = prompt('Enter any color you want to add in the beginning')
21+
let color_asking2 = prompt('Enter any color you want to add in the end')
22+
23+
color.unshift(color_asking)
24+
document.write('Adding user color in the beginning of the array:' + color + '<br>')
25+
26+
color.push(color_asking2)
27+
document.write('Adding user color in the end of the array:' + color + '<br>')
28+
29+
color.unshift('blue', 'pink')
30+
document.write('Adding two color in the beginning of the array:' + color + '<br>')
31+
32+
color.shift()
33+
document.write('Deleting the first color in the array:' + color + '<br>')
34+
35+
color.pop()
36+
document.write('Deleting the last color in the array:' + color + '<br>')
37+
38+
39+
let index_asking = prompt('Enter at what position/index you want to add the color')
40+
let color_asking_name = prompt('Enter the color name you want to add at ' + index_asking + ' position')
41+
42+
color[index_asking] = [color_asking_name]
43+
document.write('Adding color at specific index by asking user:' + color + '<br>')
44+
45+
let color_count = prompt('How many colors you want to delete')
46+
47+
for (let index = 0; index < color_count; index++) {
48+
let index_asking2 = prompt('Enter at what position/index you want to delete the color')
49+
color[index_asking2] = []
50+
document.write('Deleting color at specific index by asking user:' + color)
51+
}
52+
53+
let numbers = [320, 230, 480, 120]
54+
document.write('Scores of Students : ' + numbers + '<br>')
55+
56+
numbers.sort(function (a, b) {
57+
return a - b;
58+
});
59+
document.write('Ordered Scores of Students : ' + numbers, '<br> <br>');
60+
61+
62+
document.write('Cities list: <br>')
63+
let cities = ['Karachi', 'Lahore', 'Islamabad', 'Quetta', 'Peshawar <br> <br>']
64+
document.write(cities)
65+
66+
document.write('Selected cities list <br>')
67+
let selectedCities = ['Islamabad', 'Quetta', 'Peshawar <br> <br>']
68+
document.write(selectedCities)
69+
70+
var arr = ['This', 'is', 'my', 'cat'];
71+
document.write('Array: <br> ' + arr + '<br> <br>')
72+
73+
var joining_arr = arr.join(' ');
74+
document.write('Array: <br> ' + joining_arr + '<br> <br>')
75+
76+
let devices = ['keyboard', 'mouse', 'printer', 'moniter']
77+
document.write('Devices: <br>' + devices + '<br>')
78+
79+
document.write(devices + '<br> <br>')
80+
81+
let devices2 = ['keyboard', 'mouse', 'printer', 'moniter']
82+
document.write('Devices: <br>' + devices + '<br>')
83+
84+
let devices_reverse = devices2.reverse();
85+
document.write(devices_reverse + '<br> <br>')
86+
87+
let phone_manufacturers = ['Apple <br>' + 'Samsung <br>' + 'Motorola <br>' + 'Nokia <br>' + 'Sony <br>' + 'Haier <br>']
88+
document.write(phone_manufacturers)

Task4.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Javascript Task4</title>
8+
<link rel="stylesheet" href="style.css">
9+
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon">
10+
</head>
11+
12+
<body>
13+
<div class="container">
14+
<a href="index.html"><button>Home</button></a>
15+
<a href="Task1.html"><button>Task 1</button></a>
16+
<a href="Task2.html"><button>Task 2</button></a>
17+
<a href="Task3.html"><button>Task 3</button></a>
18+
<a href="#"><button>Task 4</button></a>
19+
</div>
20+
21+
<script src="Task4.js"></script>
22+
</body>
23+
24+
</html>

0 commit comments

Comments
 (0)