├── index.html
└── script.js
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Math Expression
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/script.js:
--------------------------------------------------------------------------------
1 | // Q1: Write a program that take two numbers & add them in a new variable and how the result in
2 | // browser (Sum Of 3 And 5 is 8);
3 |
4 | let num1 = 5;
5 | let num2 = 3;
6 | let sum = num1 + num2;
7 | document.write(`Sum of 5 & 3 is ${sum}
`);
8 |
9 | // Q2: Reapeat Task 1 For Subtraction Multiplication Division And Modulus.
10 | let difference = num1 - num2;
11 | document.write(`Difference of 5 & 3 is ${difference}
`);
12 | let product = num1 * num2;
13 | document.write(`Product of 5 & 3 is ${product}
`);
14 | let division = num1 / num2;
15 | document.write(`Division of 5 & 3 is ${division.toFixed(3)}
`);
16 | let modulus = num1 % num2;
17 | document.write(`Modulus of 5 & 3 is ${modulus}
`);
18 |
19 | // Q3: Do The Following using JS Mathematic Expressions;
20 | // a) Declare a Variable ;
21 | // b) Show the value of variable in your browser;
22 | // c) Initialize The Variable with some number ;
23 | // d) Show the value of variable in your browser like Initial Value 5;
24 | // e) Increment The Variable ;
25 | // f) Show the value of increment variable in your browser like value after increment is 6;
26 | // g) add 7 to the variable ;
27 | // h) Show the value of variable in your browser like value after addition is 13;
28 | // i) decrement The Variable ;
29 | // J) Show the value of variable in your browser like value after decrement is 12;
30 | // k) Now modulus answer by 3;
31 | // l) Show the reminder in your browser like Reminder is 0;
32 |
33 | let number;
34 | document.write(`The value of number is ${number}
`);
35 | number = 5;
36 | document.write(`Initial Value of number is ${number}
`);
37 | number++;
38 | document.write(`Value of number after increment is ${number}
`);
39 | number += 7;
40 | document.write(`Value of number after addition is ${number}
`);
41 | number--;
42 | document.write(`Value of number after decrement is ${number}
`);
43 | number %= 3;
44 | document.write(`Reminder of number after modulus of it by 3 is ${number}
`);
45 |
46 | // Q4: cost one 1 movie ticket is 600 find the cost of 5 tickets store in variable
47 |
48 | let ticketPrice = 600;
49 | let fiveTicketPrice = ticketPrice * 5;
50 | document.write(`The cost of one movie ticket is ${ticketPrice} and cost of 5 movie ticket is ${fiveTicketPrice}
`);
51 |
52 | // Q5: write a script to display a table of any number in a browser
53 |
54 | let userInput = +prompt("Enter a Number");
55 | for (let i = 1; i <= 10; i++) {
56 | document.write(`${userInput} X ${i} = ${userInput * i}
`);
57 | }
58 |
59 | // Q6: Make A Temperature Converter Based on the following step
60 | // a)Store a Celsius temperature into a variable
61 | // b)Convert it to Fahrenheit & output "NNOC is NNOF"
62 | // c)Now store a Fahrenheit temperature into a variable
63 | // d)Convert it to Celsius & output “NNF is NN.C"
64 |
65 | let tempInCelsius = 25;
66 | let tempInFahrenheit = (tempInCelsius * 9 / 5) + 32;
67 | document.write(`
${tempInCelsius}°C is ${tempInFahrenheit}°F
`);
68 | tempInFahrenheit = 70;
69 | tempInCelsius = (tempInFahrenheit - 32) * 5 / 9;
70 | document.write(`${tempInFahrenheit}°F is ${tempInCelsius.toFixed(2)}°C
`);
71 |
72 | // Q7: Write a Program To Impliment Check Out Process
73 | // a. Price of item 1
74 | // b. Price of item 2
75 | // c. Ordered quantity of item 1
76 | // d. Ordered Quantity of item 2
77 | // e. Shipping charge
78 |
79 | let priceOfItem1 = 650;
80 | let priceOfItem2 = 100;
81 | let orderedQuantityOfItem1 = 3;
82 | let orderedQuantityOfItem2 = 7;
83 | let shippingCharges = 100;
84 | const totalCost = priceOfItem1 * orderedQuantityOfItem1 + priceOfItem2 * orderedQuantityOfItem2 + shippingCharges;
85 | document.write(` Shopping Cart
`);
86 | document.write(`Price of item 1: ${priceOfItem1}
`);
87 | document.write(`Quantity of item 1: ${orderedQuantityOfItem1}
`);
88 | document.write(`Price of item 2: ${priceOfItem2}
`);
89 | document.write(`Quantity of item 2: ${orderedQuantityOfItem2}
`);
90 | document.write(`Shipping Charges: ${shippingCharges}
`);
91 | document.write(`Total cost of your order: ${totalCost}
`);
92 |
93 | // Q8: Store a total marks and obtained marks in 2 variable and compute the percentage
94 |
95 | let totalMarks = 980;
96 | let obtainedMarks = 805;
97 | const percentage = obtainedMarks / totalMarks * 100;
98 | document.write(` Marksheet
Total Marks : ${totalMarks}
Obtained Marks : ${obtainedMarks}
Percentage : ${percentage.toFixed(2)}
`);
99 |
100 | // 9. Assume we have 10 US dollars & 25 Saudi Riyals. Write a
101 | // script to convert the total currency to Pakistani Rupees.
102 | // Perform all calculations in a single expression.
103 | // (Exchange rates : 1 US Dollar = 278.33 Pakistani Rupee
104 | // and 1 Saudi Riyal = 74.22 Pakistani Rupee)
105 |
106 | let totalCurrencyInPKR = 10 * 278.33 + 25 * 74.22;
107 | document.write(` Currency in PKR
Total Currency in PKR : ${totalCurrencyInPKR.toFixed(2)}
`);
108 |
109 | // Q:10 Write a program to initialize a variable with some
110 | // number and do arithmetic in following sequence:
111 | // a. Add 5
112 | // b. Multiply by 10
113 | // c. Divide the result by 2
114 | // Perform all calculations in a single expression
115 |
116 | const initialNumber = 10;
117 | const result = (initialNumber + 5) * 10 / 2;
118 | document.write(`Initial Number is ${initialNumber}
`);
119 | document.write(`The Result Of Calculation is ${result}
`);
120 |
121 | // Q:11 The Age Calculator: Forgot How Old Someone is? Calculate it
122 | // a. Store the current year in a variable
123 | // b. Store their birth year in a variable
124 | // c. Calculate their 2 possible ages based on the stored values
125 | // assuming the person has already had their birthday this year
126 | // Output them to the screen like so: years old
127 |
128 | let currentYear = 2024;
129 | const birthYear = 2007;
130 | const age1 = currentYear - birthYear;
131 | const age2 = age1 - 1;
132 | document.write(` Age Calculator
Current Year : ${currentYear}
Birth Year : ${birthYear}
Your Age is: ${age1} or ${age2}
`);
133 |
134 | // Q:12 The Geomatrizer : Calculate The Properties Of circle
135 | // a. Store a radius of circle in a variable
136 | // b. Calculate the circumference based on the radius and output The Circumference is ??
137 | // c. also calculate the area of circle and output the area the area of circle is ??
138 |
139 | let radiusOfCircle = 20;
140 | const circumference = 2 * 3.14 * radiusOfCircle;
141 | const areaOfCircle = 3.14 * (radiusOfCircle*radiusOfCircle);
142 | document.write(` The Geomatrizer
The Circumference Of Circle is ${circumference.toFixed(2)}
`);
143 | document.write(`The Area Of Circle is ${areaOfCircle}
`);
144 |
145 | // Q13: The Lifetime Supply Calculator: Ever wonder how
146 | // much a “lifetime supply” of your favorite snack is?
147 | // Wonder no more.
148 | // a. Store your favorite snack into a variable
149 | // b. Store your current age into a variable.
150 | // c. Store a maximum age into a variable.
151 | // d. Store an estimated amount per day (as a number).
152 | // e. Calculate how many would you eat total for the rest of
153 | // your life.
154 | // Output the result to the screen like so: “You will need
155 | // NNNN to last you until the ripe old age of NN”.
156 |
157 | const snack = "Chocolates";
158 | const currentAge = 16;
159 | const maxAge = 100;
160 | const amountPerDay = 2;
161 | const totalNeeded = (maxAge - currentAge) * 365 * amountPerDay;
162 | document.write(` The Lifetime Supply Calculator
`);
163 | document.write(`Favorite Snack : ${snack}
`);
164 | document.write(`Current Age : ${currentAge}
`);
165 | document.write(`Estimated Maximum Age : ${maxAge}
`);
166 | document.write(`Amount Of Snack Per Day : ${amountPerDay}
`);
167 | document.write(`You will need ${totalNeeded} ${snack} to last you until the reach old age of ${maxAge}
`);
168 |
169 | /////////////////////////////////////////// The End ////////////////////////////////////////////////
--------------------------------------------------------------------------------