Skip to content

Commit b9b045b

Browse files
committed
Add chapters from9 to 16
1 parent 9cfec7e commit b9b045b

9 files changed

Lines changed: 635 additions & 0 deletions

File tree

chapter 12 to 13/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Chapter 12 to 13 Task | IF…ELSE & ELSE IF STATEMENT,
7+
TESTING SET OF CONDITIONS </title>
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
<body>
11+
<script src="script.js"></script>
12+
</body>
13+
</html>

chapter 12 to 13/script.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
document.write(`<h2>IF…ELSE & ELSE IF STATEMENT,
2+
TESTING SET OF CONDITIONS</h2>`);
3+
4+
// Question# 1:
5+
// Write a program that takes a character (number or string)
6+
// in a variable & checks whether the given input is a
7+
// number, uppercase letter or lower case letter. (Hint: ASCII
8+
// codes:- A=65, Z=90, a=97, z=122).
9+
10+
var char = prompt("Enter a Character");
11+
document.write(`Character is ${char}</br>`);
12+
if (char == Number.parseInt(char)) {
13+
document.write(`Input is a number </br> </br>`);
14+
} else if (char == char.toUpperCase()) {
15+
document.write(`Input is an uppercase letter </br></br>`);
16+
} else if (char == char.toLowerCase()) {
17+
document.write(`Input is an lowercase letter </br></br>`);
18+
} else {
19+
document.write(`Invalid Character! </br></br>`);
20+
}
21+
22+
// Question# 2:
23+
// 2. Write a JavaScript program that accept two integers and
24+
// display the larger. Also show if the two integers are equal.
25+
var int_1 = Number.parseInt(prompt("Enter First integer!"));
26+
var int_2 = Number.parseInt(prompt("Enter Second integer!"));
27+
28+
document.write(`First integer: ${int_1} </br>`);
29+
document.write(`Second integer: ${int_2}</br>`);
30+
31+
if (int_1 == int_2) {
32+
document.write(`First integer is equal to Second integer </br></br>`);
33+
} else if (int_1 > int_2) {
34+
document.write(`First integer is larger than Second integer </br></br> `);
35+
} else {
36+
document.write(`Second integer is larger than First integer </br></br>`);
37+
}
38+
39+
// Question# 3:
40+
// 3. Write a program that takes input a number from user &
41+
// state whether the number is positive, negative or zero.
42+
43+
var user_num = Number.parseInt(
44+
prompt("Enter a number whether check number positive, negative or zero")
45+
);
46+
document.write(`User Number: ${user_num} </br>`);
47+
48+
if (user_num > 0) {
49+
document.write(`User number is positive </br></br>`);
50+
} else if (user_num < 0) {
51+
document.write(`User number is Negative </br></br>`);
52+
} else {
53+
document.write(`User number is Zero </br></br>`);
54+
}
55+
56+
// Question# 4:
57+
// 4. Write a program that takes a character (i.e. string of
58+
// length 1) and returns true if it is a vowel, false otherwise
59+
var character = prompt("Enter a Character! (Vowel or not)");
60+
var vowels = ["a", "e", "i", "o", "u"];
61+
document.write(`Character: ${character}</br>`);
62+
if (
63+
character == vowels[0] ||
64+
character == vowels[1] ||
65+
character == vowels[2] ||
66+
character == vowels[3] ||
67+
character == vowels[4]
68+
) {
69+
document.write(`it is a vowel </br></br>`);
70+
} else {
71+
document.write(`it is not vowel</br></br>`);
72+
}
73+
74+
// Question# 5:
75+
// 5. Write a program that
76+
// a. Store correct password in a JS variable.
77+
// b. Asks user to enter his/her password
78+
// c. Validate the two passwords:
79+
// i.
80+
// Check if user has entered password. If not, then
81+
// give message “ Please enter your password”
82+
// ii.
83+
// Check if both passwords are same. If they are
84+
// same, show message “Correct! The password you
85+
// entered matches the original password”. Show
86+
// “Incorrect password” otherwise.
87+
88+
var correct_pswd = "sadaf";
89+
var user_pswd = prompt("Enter Your Password!");
90+
91+
if (user_pswd == "") {
92+
alert(`Please enter your password!`);
93+
document.write(`Please enter your password!`);
94+
} else if (user_pswd == correct_pswd) {
95+
document.write(
96+
`Correct! The password you entered matches the original password </br></br>`
97+
);
98+
} else {
99+
document.write(`Incorrect password </br></br>`);
100+
}
101+
102+
// Question# 6:
103+
104+
// 6.
105+
// This if/else statement does not work. Try to fix it:
106+
var greeting;
107+
var hour = 20;
108+
if (hour < 18) {
109+
document.write((greeting = "Good day </br></br>"));
110+
} else {
111+
document.write((greeting = "Good evening </br></br>"));
112+
}
113+
114+
// Question# 7:
115+
// 7. Write a program that takes time as input from user in 24
116+
// hours clock format like: 1900 = 7pm. Implement the
117+
// following case using if, else & else if statements
118+
119+
var time = 1900;
120+
121+
var user_time = Number.parseInt(prompt("Enter 24 hours clock format time"));
122+
if (user_time >= 0 && user_time < 1200) {
123+
document.write(`Good Morning! </br></br>`);
124+
} else if (user_time >= 1200 && user_time < 1700) {
125+
document.write(`Good Afternoon! </br></br>`);
126+
} else if (user_time >= 1700 && user_time < 2100) {
127+
document.write(`Good Evening! </br></br>`);
128+
} else if (user_time >= 2100 && user_time <= 2359) {
129+
document.write(`Good Night! </br></br>`);
130+
}

chapter 12 to 13/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*{
2+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
3+
}

chapter 14 to 16/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Chapter 14 to 16 Task | ARRAYS</title>
7+
<link rel="stylesheet" href="style.css" />
8+
</head>
9+
<body>
10+
11+
12+
<script src="script.js"></script>
13+
</body>
14+
</html>

chapter 14 to 16/script.js

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
document.write(`<h2>ARRAYS</h2>`);
2+
3+
// Question# 1:
4+
// 1. Declare an empty array using JS literal notation to store
5+
// student names in future.
6+
// Question# 2:
7+
// 2. Declare an empty array using JS object notation to store
8+
// student names in future.
9+
10+
var std_names = [];
11+
12+
// Question# 3:
13+
// 3. Declare and initialize a strings array.
14+
var friend_name = ["Ummulqura", "Ramla", "Maheen", "Sakina", "Usbah"];
15+
16+
// Question# 4:
17+
// 4. Declare and initialize a numbers array.
18+
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
19+
20+
// Question# 5:
21+
// 5. Declare and initialize a boolean array.
22+
var conditional = [true, false, true, true, false, false];
23+
24+
// Question# 6:
25+
// 6. Declare and initialize a mixed array.
26+
var mixed_arr = ["Aleena", 5, false, 6, 10, true, "Aleeza"];
27+
28+
// Question# 7:
29+
// 7. Declare and Initialize an array and store available
30+
// education qualifications in Pakistan (e.g. SSC, HSC, BCS,
31+
// BS, BCOM, MS, M. Phil., PhD). Show the listed
32+
// qualifications in your browser like:
33+
34+
// document.write(`<h3>Qualifications</h3>`);
35+
// var edu_qualifi = ["SSC", "HSC", "BCS", "BS", "BCOM", "MS", "M.Phil", "PhD"];
36+
// document.write(`1) ${edu_qualifi[0]} </br>`);
37+
// document.write(`2) ${edu_qualifi[1]} </br>`);
38+
// document.write(`3) ${edu_qualifi[2]} </br>`);
39+
// document.write(`4) ${edu_qualifi[3]} </br>`);
40+
// document.write(`5) ${edu_qualifi[4]} </br>`);
41+
// document.write(`6) ${edu_qualifi[5]} </br>`);
42+
// document.write(`7) ${edu_qualifi[6]} </br>`);
43+
// document.write(`8) ${edu_qualifi[7]} </br> </br>`);
44+
45+
// Question# 8:
46+
// Write a program to store 3 student names in an array.Take
47+
// another array to store score of these three students.
48+
// Assume that total marks are 500 for each student, display
49+
// the scores & percentages of students like:
50+
51+
// var stud_name = ["Izma", "Naddiya", "Ayesha"];
52+
// var stud_score = [400, 490, 400];
53+
// var total_marks = 500;
54+
// let stud1_per = (stud_score[0] / total_marks) * 100;
55+
// let stud2_per = (stud_score[1] / total_marks) * 100;
56+
// let stud3_per = (stud_score[2] / total_marks) * 100;
57+
58+
// document.write(
59+
// `Score of ${stud_name[0]} is ${stud_score[0]}. Percentage: ${stud1_per}% </br>`
60+
// );
61+
// document.write(
62+
// `Score of ${stud_name[1]} is ${stud_score[1]}. Percentage: ${stud2_per}% </br> `
63+
// );
64+
// document.write(
65+
// `Score of ${stud_name[2]} is ${stud_score[2]}. Percentage: ${stud3_per}% </br> </br> `
66+
// );
67+
68+
// Question# 9:
69+
// Initialize an array with color names. Display the array
70+
// elements in your browser.
71+
72+
// var color = ["red", "blue", "green", "black", "yellow"];
73+
// document.write(`${color} </br>`);
74+
// // a. Ask the user what color he/she wants to add to the
75+
// // beginning & add that color to the beginning of the array.
76+
// var user_color = prompt("Enter a color to add in beginning of the array");
77+
// color.unshift(user_color);
78+
// // Display the updated array in your browser.
79+
// document.write(`${color} </br>`);
80+
// // b. Ask the user what color he/she wants to add to the end
81+
// // & add that color to the end of the array. Display the
82+
// // updated array in your browser.
83+
84+
// var user_color1 = prompt("Enter a color to add in End of the array");
85+
// color.push(user_color1);
86+
// document.write(`${color} </br>`);
87+
// // c. Add two more color to the beginning of the array.
88+
// // Display the updated array in your browser.
89+
// color.unshift("pink", "parrot");
90+
// document.write(`${color} </br>`);
91+
92+
// // d. Delete the first color in the array. Display the updated
93+
// // array in your browser.
94+
// color.shift();
95+
// document.write(`${color} </br>`);
96+
97+
// // e. Delete the last color in the array. Display the updated
98+
// // array in your browser.
99+
// color.pop();
100+
// document.write(`${color} </br>`);
101+
102+
// // f. Ask the user at which index he/she wants to add a color
103+
// // & color name. Then add the color to desired
104+
// // position/index. . Display the updated array in your
105+
// // browser.
106+
// var user_index = prompt("At which index you want to add color?");
107+
// var user_color2 = prompt("Enter a color to add the color to desired index!");
108+
// color.splice(user_index, 0, user_color2);
109+
// document.write(`${color} </br>`);
110+
111+
// // g. Ask the user at which index he/she wants to delete
112+
// // color(s) & how many colors he/she wants to delete. Then
113+
// // remove the same number of color(s) from user-defined
114+
// // position/index.Display the updated array in your
115+
// // browser.
116+
// var user_index1 = prompt("At which index you want to delete color");
117+
// var delete_clr = prompt("how many colors you want to delete?");
118+
// color.splice(user_index1, delete_clr);
119+
// document.write(`${color} </br> </br>`);
120+
121+
// Question# 10:
122+
// 'Write a program to store student scores in an array &
123+
// sort the array in ascending order using Array’s sort
124+
// method. '
125+
var std_scores = [260, 450, 100, 200, 250, 240, 350, 105, 112];
126+
document.write(`Score of Students: ${std_scores} </br>`);
127+
std_scores.sort();
128+
document.write(`Order Score of Students: ${std_scores} </br> </br>`);
129+
130+
// Question# 11:
131+
// Write a program to initialize an array with city names.
132+
// Copy 3 array elements from cities array to selectedCities
133+
// array.
134+
135+
var city_name = [
136+
"Karachi",
137+
"Islamabad",
138+
"Lahore",
139+
"Multan",
140+
"Quetta",
141+
"Peshawar",
142+
"Rawalpindi",
143+
];
144+
document.write(`Cities List:</br> ${city_name} </br>`);
145+
var selected_cities = ["Karachi", "Islamabad", "Quetta"];
146+
document.write(`selected Cities List: </br> ${selected_cities} </br> </br>`);
147+
148+
// Question# 12:
149+
// Write a program to create a single string from the
150+
// below mentioned array:
151+
var arr = ["This", "is", " my", "cat"];
152+
// (Use array’s join method)
153+
var sentence = arr.join(" ");
154+
document.write(`${sentence} </br></br>`);
155+
156+
// Question# 13:
157+
158+
// Create a new array. Store values one by one in such a way
159+
// that you can access the values in the order in which they
160+
// were stored. (FIFO-First In First Out)
161+
162+
var elec_appliances = ["Fridge", "Fan", "Room Cooler", "Ac", "Iron", "Grinder"];
163+
document.write(`Out: </br> ${elec_appliances[0]}</br>`);
164+
document.write(`Out: </br> ${elec_appliances[1]}</br>`);
165+
document.write(`Out: </br> ${elec_appliances[2]}</br>`);
166+
document.write(`Out: </br> ${elec_appliances[3]}</br>`);
167+
document.write(`Out: </br> ${elec_appliances[4]}</br>`);
168+
document.write(`Out: </br> ${elec_appliances[5]}</br></br>`);
169+
170+
// Question# 14:
171+
// Create a new array. Store values one by one in such a way
172+
// that you can access the values in reverse order. (Last In
173+
// First Out)
174+
var fabric = [
175+
"Lawn",
176+
"Silk",
177+
"Cotton",
178+
"Tissue",
179+
"Pluster Cotton",
180+
"Georgette",
181+
];
182+
document.write(`Out: </br> ${fabric[5]}</br>`);
183+
document.write(`Out: </br> ${fabric[4]}</br>`);
184+
document.write(`Out: </br> ${fabric[3]}</br>`);
185+
document.write(`Out: </br> ${fabric[2]}</br>`);
186+
document.write(`Out: </br> ${fabric[1]}</br>`);
187+
document.write(`Out: </br> ${fabric[0]}</br></br>`);
188+
189+
// Question# 15:
190+
// Write a program to store phone manufacturers (Apple,
191+
// Samsung, Motorola, Nokia, Sony & Haier) in an array.
192+
// Display the following dropdown/select menu in your
193+
// browser using document.write() method:
194+
195+
var ph_manufac = ["Apple", "Samsung", "Motorola", "Nokia", "Sony", "Haier"];
196+
197+
document.write(
198+
`<form action="">
199+
<select name="phone-manufacturer">
200+
<option value="${ph_manufac[0]}">${ph_manufac[0]}</option>
201+
<option value="${ph_manufac[1]}">${ph_manufac[1]}</option>
202+
<option value="${ph_manufac[2]}">${ph_manufac[2]}</option>
203+
<option value="${ph_manufac[3]}">${ph_manufac[3]}</option>
204+
<option value="${ph_manufac[4]}">${ph_manufac[4]}</option>
205+
<option value="${ph_manufac[5]}">${ph_manufac[5]}</option>
206+
</select>
207+
</form>`
208+
);

chapter 14 to 16/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*{
2+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
3+
}

chapter 9 to 11/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Chapter 9 to 11 Task | USER INPUT & CONDITIONAL
7+
STATEMENT </title>
8+
<link rel="stylesheet" href="style.css">
9+
</head>
10+
<body>
11+
<script src="script.js"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)