Skip to content

Commit 9cfec7e

Browse files
committed
Add Chapter 5 & 6 Assignment
1 parent 20551ca commit 9cfec7e

6 files changed

Lines changed: 409 additions & 0 deletions

File tree

chapter 5/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 5 Task | MATH EXPRESSIONS </title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
11+
<script src="script.js"></script>
12+
</body>
13+
</html>

chapter 5/script.js

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
// Question# 1:
2+
//Write a program that take two numbers &
3+
//add them in a new variable. Show the result in your browser.
4+
5+
document.write(`<h2> Familiar Expression </h2>`);
6+
7+
var num1 = 10;
8+
var num2 = 2;
9+
let add = num1 + num2;
10+
document.write(`Sum of ${num1} and ${num2} is ${add} </br>`);
11+
12+
// Question# 2 :
13+
//Repeat task1 for subtraction,
14+
//multiplication, division & modulus.
15+
16+
// subtraction:
17+
let subtract = num1 - num2;
18+
document.write(`Subtraction of ${num1} and ${num2} is ${subtract} </br>`);
19+
// multiplication:
20+
let multiplication = num1 * num2;
21+
document.write(
22+
`Multiplication of ${num1} and ${num2} is ${multiplication} </br>`
23+
);
24+
// division:
25+
let division = num1 / num2;
26+
document.write(`Division of ${num1} and ${num2} is ${division} </br>`);
27+
// modulus:
28+
let modulus = num1 % num2;
29+
document.write(
30+
`Modulus of ${num1} and ${num2} is ${modulus} </br> </br> </br>`
31+
);
32+
33+
//Question 3:
34+
// Do the following using JS Mathematic Expressions
35+
// a. Declare a variable.
36+
// b. Show the value of variable in your browser like “Value
37+
// after variable declaration is: ??”.
38+
// c. Initialize the variable with some number.
39+
// d. Show the value of variable in your browser like “Initial
40+
// value: 5”.
41+
// e. Increment the variable.
42+
// f. Show the value of variable in your browser like “Value
43+
// after increment is: 6”.
44+
// g. Add 7 to the variable.
45+
// h. Show the value of variable in your browser like “Value
46+
// after addition is: 13”.
47+
// i. Decrement the variable.
48+
// j. Show the value of variable in your browser like “Value
49+
// after decrement is: 12”.
50+
// k. Show the remainder after dividing the variable’s value
51+
// by 3.
52+
// l. Output : “The remainder is : 0”.
53+
54+
var value;
55+
document.write(`Value after variable declaration is ${value} </br>`);
56+
value = 5;
57+
document.write(`Initial Value is ${value} </br>`);
58+
value++;
59+
document.write(`Value of variable after increment is ${value} </br>`);
60+
value += 7;
61+
document.write(`Value of variable after addition is ${value} </br>`);
62+
value--;
63+
document.write(`Value of variable after decrement is ${value} </br>`);
64+
value %= 3;
65+
document.write(
66+
`The remainder after division of variable's value is ${value} </br> </br>`
67+
);
68+
69+
//Question 4:
70+
71+
// Cost of one movie ticket is 600 PKR. Write a script to
72+
// store ticket price in a variable & calculate the cost of buying 5
73+
// tickets to a movie. Example output:
74+
75+
document.write(`<h2> Cost Calculation:</h2> `);
76+
var ticket_price = 600;
77+
var ticket_qty = 5;
78+
var output = ticket_price * ticket_qty;
79+
document.write(
80+
`Total cost to buy ${ticket_qty} tickets to a movie is ${output} </br> </br> `
81+
);
82+
83+
//Question 5:
84+
85+
// Write a script to display multiplication table of any
86+
// number in your browser
87+
88+
document.write(`<h2> Table of 4 </h2> `);
89+
var table = 4;
90+
document.write(`${table} x 1 = ${table * 1} </br> `);
91+
document.write(`${table} x 2 = ${table * 2} </br> `);
92+
document.write(`${table} x 3 = ${table * 3} </br> `);
93+
document.write(`${table} x 4 = ${table * 4} </br> `);
94+
document.write(`${table} x 5 = ${table * 5} </br> `);
95+
document.write(`${table} x 6 = ${table * 6} </br> `);
96+
document.write(`${table} x 7 = ${table * 7} </br> `);
97+
document.write(`${table} x 8 = ${table * 8} </br> `);
98+
document.write(`${table} x 9 = ${table * 9} </br> `);
99+
document.write(`${table} x 10 = ${table * 10} </br> </br></br>`);
100+
101+
//Question 6:
102+
103+
// The Temperature Converter: It’s hot out! Let’s make a
104+
// converter based on the steps here.
105+
// a. Store a Celsius temperature into a variable.
106+
// b. Convert it to Fahrenheit & output “NNoC is NNoF”.
107+
// c. Now store a Fahrenheit temperature into a variable.
108+
// d. Convert it to Celsius & output “NNoF is NNoC”.
109+
110+
document.write(`<h2>Celsius Temperature Calculation </h2>`);
111+
112+
var fahr_temp = 70;
113+
var cels_calc = (fahr_temp - 32) * (5 / 9);
114+
document.write(
115+
`${fahr_temp}<sup>0</sup>F is ${cels_calc}<sup>0</sup>C </br></br>`
116+
);
117+
118+
document.write(`<h2>Fahrenheit Temperature Calculation </h2>`);
119+
120+
var cels_temp = 25;
121+
var fahr_calc = cels_temp * (9 / 5) + 32;
122+
document.write(`${cels_temp}<sup>0</sup>C is ${fahr_calc}<sup>0</sup>F </br>`);
123+
124+
//Question 7:
125+
// Write a program to implement checkout process of a
126+
// shopping cart system for an e-commerce website. Store
127+
// the following in variables
128+
// a. Price of item 1
129+
// b. Price of item 2
130+
// c. Ordered quantity of item 1
131+
// d. Ordered Quantity of item 2
132+
// e. Shipping charges
133+
// Compute the total cost & show the receipt in your browser.
134+
135+
document.write(`<h2>Shopping Cart</h2>`);
136+
var item1 = 650;
137+
var item2 = 100;
138+
var item1_qty = 3;
139+
var item2_qty = 7;
140+
var Shipping_charges = 100;
141+
var item1_cost = item1 * item1_qty;
142+
var item2_cost = item2 * item2_qty;
143+
var total_cost = item1_cost + item2_cost + Shipping_charges;
144+
145+
document.write(`Price of Item 1 is ${item1} </br>`);
146+
document.write(`Quantity of Item 1 is ${item1_qty} </br>`);
147+
document.write(`Price of Item 2 is ${item2} </br>`);
148+
document.write(`Quantity of Item 2 is ${item2_qty} </br>`);
149+
document.write(`Shipping Charges ${Shipping_charges} </br></br>`);
150+
document.write(`Total cost of your order is ${total_cost}</br></br> `);
151+
152+
//Question 8:
153+
154+
// Store total marks & marks obtained by a student in 2
155+
// variables. Compute the percentage & show the result in
156+
// your browser
157+
document.write(`<h2>Marks Sheet </h2>`);
158+
var total_marks = 980;
159+
var Obt_marks = 804;
160+
let percentage = (Obt_marks / total_marks) * 100;
161+
162+
document.write(`Total Marks:${total_marks}</br>`);
163+
document.write(`Marks Obtained: ${Obt_marks}</br>`);
164+
document.write(`Percentage${percentage}&percnt; </br></br>`);
165+
166+
//Question 9:
167+
168+
// Assume we have 10 US dollars & 25 Saudi Riyals. Write a
169+
// script to convert the total currency to Pakistani Rupees.
170+
// Perform all calculations in a single expression.
171+
// (Exchange rates : 1 US Dollar = 104.80 Pakistani Rupee
172+
// and 1 Saudi Riyal = 28 Pakistani Rupee)
173+
document.write(`<h2>Currency in PKR</h2>`);
174+
var us_dollars = 10;
175+
var saudi_riyals = 25;
176+
177+
var exchange_rate = us_dollars * 104.8 + saudi_riyals * 28;
178+
document.write(`Total Currency in PKR: ${exchange_rate} </br></br>`);
179+
180+
//Question 10:
181+
// Write a program to initialize a variable with some
182+
// number and do arithmetic in following sequence:
183+
// a. Add 5
184+
// b. Multiply by 10
185+
// c. Divide the result by 2
186+
// Perform all calculations in a single expression
187+
188+
var numb = 4;
189+
var calc = ((4 + 5) * 10) / 2;
190+
191+
//Question 11:
192+
// The Age Calculator: Forgot how old someone is?
193+
// Calculate it!
194+
// a. Store the current year in a variable.
195+
// b. Store their birth year in a variable.
196+
// c. Calculate their 2 possible ages based on the stored
197+
// values.
198+
199+
document.write(`<h2>Age Calculator</h2>`);
200+
201+
var current_year = 2010;
202+
var birth_year = 2005;
203+
var age = current_year - birth_year;
204+
document.write(`Current year: ${current_year} </br>`);
205+
document.write(`Birth year: ${birth_year}</br>`);
206+
document.write(`Your age is: ${age}</br> </br>`);
207+
208+
//Question 12:
209+
// The Geometrizer: Calculate properties of a circle.
210+
// a. Store a radius into a variable.
211+
// b. Calculate the circumference based on the radius, and
212+
// output “The circumference is NN”.
213+
// (Hint : Circumference of a circle = 2 π r , π = 3.142)
214+
// Calculate the area based on the radius, and output “The
215+
// area is NN”. (Hint : Area of a circle = π r2, π = 3.142)
216+
217+
document.write(`<h2>The Geometrizer</h2>`);
218+
var radius = 20;
219+
var pie_value = 3.142;
220+
var circumference = `${2 * pie_value * radius}`;
221+
document.write(`Radius of a circle : ${radius} </br>`);
222+
document.write(`The circumference is: ${circumference}</br>`);
223+
document.write(`The area is: ${pie_value * radius ** 2}</br></br>`);
224+
225+
//Question 13:
226+
// The Lifetime Supply Calculator: Ever wonder how
227+
// much a “lifetime supply” of your favorite snack is?
228+
// Wonder no more.
229+
// a. Store your favorite snack into a variable
230+
// b. Store your current age into a variable.
231+
// c. Store a maximum age into a variable.
232+
// d. Store an estimated amount per day (as a number).
233+
// e. Calculate how many would you eat total for the rest of
234+
// your life.
235+
// Output the result to the screen like so: “You will need
236+
// NNNN to last you until the ripe old age of NN”.
237+
document.write(`<h2>The Lifetime Supply Calculator</h2>`);
238+
239+
var favorite_snacks = "Chillz";
240+
var curr_age = 14;
241+
var max_age = 50;
242+
var amount_per_snack = 10;
243+
var snack_qty = 1000;
244+
245+
document.write(`Favourite Snack: ${favorite_snacks} </br>`);
246+
document.write(`Current Age: ${curr_age} </br>`);
247+
document.write(`Estimated Maximum Age: ${max_age} </br>`);
248+
document.write(`Amountof Snacks per day: ${amount_per_snack} </br>`);
249+
document.write(`Favourite Snack: ${favorite_snacks} </br>`);
250+
251+
document.write(
252+
`You will need ${snack_qty} to last you until the ripe old age of ${max_age} `
253+
);

chapter 5/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 6/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 6 Task | MATH EXPRESSIONS </title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
<script src="script.js"></script>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)