Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e4af60

Browse files
feat: add Topic2 all questions & topics
1 parent ba0ab93 commit 7e4af60

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

‎Topic2/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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>Document</title>
8+
</head>
9+
10+
<body>
11+
12+
<script src="./index.js"></script>
13+
</body>
14+
15+
</html>

‎Topic2/index.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Question: Valid user for voting
2+
let userAge = Number(prompt("What is your age?"));
3+
4+
if (isNaN(userAge)) {
5+
throw new Error('Invalid prompt');
6+
} else if (userAge >= 18) {
7+
console.log("You can vote");
8+
} else {
9+
console.log("You cannot vote");
10+
}
11+
12+
13+
// Question: Shop Discount
14+
let finalAmount = Number(prompt("What is the final amount?"));
15+
let discount = 0;
16+
if (finalAmount > 0 && finalAmount <= 5000) {
17+
discount = 0;
18+
} else if (finalAmount > 5000 && finalAmount <= 7000) {
19+
discount = 5;
20+
} else if (finalAmount > 7000 && finalAmount <= 9000) {
21+
discount = 10;
22+
} else if (finalAmount > 9000) {
23+
discount = 20;
24+
} else {
25+
throw new Error('Wrong Input');
26+
}
27+
console.log(finalAmount - Math.floor((discount * finalAmount) / 100));
28+
29+
30+
// Question: Utility Rent
31+
let electricityUnit = Number(prompt("Enter electricity unit"));
32+
let utilityAmount = 0;
33+
if (electricityUnit < 400) {
34+
utilityAmount = (electricityUnit - 400) * 13;
35+
electricityUnit = 400;
36+
}
37+
if (electricityUnit > 200 && electricityUnit <= 400) {
38+
utilityAmount += (electricityUnit - 200) * 8;
39+
electricityUnit = 200;
40+
}
41+
if (electricityUnit > 100 && electricityUnit <= 200) {
42+
utilityAmount += (electricityUnit - 100) * 6;
43+
electricityUnit = 100;
44+
}
45+
utilityAmount += electricityUnit * 4;
46+
console.log(utilityAmount);
47+
48+
49+
// Question: Rupees Denominations
50+
let pocketAmount = Number(prompt("Enter the amount you have in your pocket!"));
51+
if (pocketAmount >= 5000) {
52+
console.log("5000 notes : " + Math.floor(pocketAmount / 5000));
53+
pocketAmount = pocketAmount % 5000;
54+
}
55+
if (pocketAmount >= 1000) {
56+
console.log("1000 notes : " + Math.floor(pocketAmount / 1000));
57+
pocketAmount = pocketAmount % 1000;
58+
}
59+
if (pocketAmount >= 500) {
60+
console.log("500 notes : " + Math.floor(pocketAmount / 500));
61+
pocketAmount = pocketAmount % 500;
62+
}
63+
if (pocketAmount >= 100) {
64+
console.log("100 notes : " + Math.floor(pocketAmount / 100));
65+
pocketAmount = pocketAmount % 100;
66+
}
67+
if (pocketAmount >= 50) {
68+
console.log("50 notes : " + Math.floor(pocketAmount / 50));
69+
pocketAmount = pocketAmount % 50;
70+
}
71+
if (pocketAmount >= 20) {
72+
console.log("20 notes : " + Math.floor(pocketAmount / 20));
73+
pocketAmount = pocketAmount % 20;
74+
}
75+
if (pocketAmount >= 10) {
76+
console.log("10 notes : " + Math.floor(pocketAmount / 10));
77+
pocketAmount = pocketAmount % 10;
78+
}
79+
if (pocketAmount >= 5) {
80+
console.log("5 coins : " + Math.floor(pocketAmount / 5));
81+
pocketAmount = pocketAmount % 5;
82+
}
83+
if (pocketAmount >= 2) {
84+
console.log("2 coins : " + Math.floor(pocketAmount / 2));
85+
pocketAmount = pocketAmount % 2;
86+
}
87+
if (pocketAmount === 1) {
88+
console.log("1 coin : " + pocketAmount);
89+
}
90+
91+
92+
// Ternary operator ? :
93+
112 > 13 ? console.log("heyehye") : console.log("hoho");
94+
95+
96+
// Nested ternary operator
97+
let checkNumber = 0;
98+
console.log(checkNumber > 0 ? "Positive" : checkNumber < 0 ? "Negative" : "Zero");
99+
100+
101+
// Switch case
102+
let dayOfWeek = 2;
103+
switch (dayOfWeek) {
104+
case 1:
105+
console.log("Monday");
106+
break;
107+
case 2:
108+
console.log("Tuesday");
109+
break;
110+
default:
111+
console.log("Invalid day");
112+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /