-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
194 lines (173 loc) · 5.22 KB
/
index.html
File metadata and controls
194 lines (173 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mini Math Toolkit - Grid Layout</title>
<style>
body {
font-family: Arial, sans-serif;
background: #4d33bd;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
margin-bottom: 30px;
color: antiquewhite;
}
.grid-container {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: auto auto auto;
gap: 20px;
max-width: 1100px;
margin: 0 auto;
}
.tool {
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.tool h2 {
margin-top: 0;
color: #007bff;
}
input, button {
padding: 10px;
font-size: 16px;
margin: 5px 0;
width: 100%;
box-sizing: border-box;
}
button {
background-color: #007bff;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
.output {
margin-top: 10px;
font-weight: bold;
}
/* Special center placement for tool 5 */
.center-tool {
grid-column: 1 / span 2;
text-align: center;
}
</style>
</head>
<body>
<h1>Mini Math Toolkit 🔧</h1>
<div class="grid-container">
<!-- Top Row -->
<div class="tool">
<h2>1. Factorial Calculator</h2>
<input type="number" id="factNum" placeholder="Enter a number">
<button onclick="calcFactorial()">Calculate Factorial</button>
<div class="output" id="factResult"></div>
</div>
<div class="tool">
<h2>2. Prime Number Checker</h2>
<input type="number" id="primeNum" placeholder="Enter a number">
<button onclick="checkPrime()">Check Prime</button>
<div class="output" id="primeResult"></div>
</div>
<!-- Center Row (Table Generator) -->
<div class="tool center-tool">
<h2>5. Multiplication Table Generator</h2>
<input type="number" id="tableNum" placeholder="Enter a number">
<button onclick="generateTable()">Generate Table</button>
<div class="output" id="tableResult"></div>
</div>
<!-- Bottom Row -->
<div class="tool">
<h2>3. LCM Calculator</h2>
<input type="number" id="lcmA" placeholder="Enter first number">
<input type="number" id="lcmB" placeholder="Enter second number">
<button onclick="calcLCM()">Find LCM</button>
<div class="output" id="lcmResult"></div>
</div>
<div class="tool">
<h2>4. HCF (GCD) Calculator</h2>
<input type="number" id="hcfA" placeholder="Enter first number">
<input type="number" id="hcfB" placeholder="Enter second number">
<button onclick="calcHCF()">Find HCF</button>
<div class="output" id="hcfResult"></div>
</div>
</div>
<script>
function calcFactorial() {
let n = parseInt(document.getElementById("factNum").value);
let result = 1;
if (n < 0 || isNaN(n)) {
document.getElementById("factResult").innerText = "Please enter a non-negative number.";
return;
}
for (let i = 2; i <= n; i++) {
result *= i;
}
document.getElementById("factResult").innerText = `Factorial of ${n} is ${result}`;
}
function checkPrime() {
let n = parseInt(document.getElementById("primeNum").value);
if (n <= 1 || isNaN(n)) {
document.getElementById("primeResult").innerText = "Not a prime number.";
return;
}
for (let i = 2; i <= Math.sqrt(n); i++) {
if (n % i === 0) {
document.getElementById("primeResult").innerText = `${n} is not a prime number.`;
return;
}
}
document.getElementById("primeResult").innerText = `${n} is a prime number.`;
}
function calcLCM() {
let a = parseInt(document.getElementById("lcmA").value);
let b = parseInt(document.getElementById("lcmB").value);
if (isNaN(a) || isNaN(b) || a <= 0 || b <= 0) {
document.getElementById("lcmResult").innerText = "Enter two positive numbers.";
return;
}
let max = Math.max(a, b);
let lcm = max;
while (true) {
if (lcm % a === 0 && lcm % b === 0) break;
lcm++;
}
document.getElementById("lcmResult").innerText = `LCM of ${a} and ${b} is ${lcm}`;
}
function calcHCF() {
let a = parseInt(document.getElementById("hcfA").value);
let b = parseInt(document.getElementById("hcfB").value);
if (isNaN(a) || isNaN(b) || a <= 0 || b <= 0) {
document.getElementById("hcfResult").innerText = "Enter two positive numbers.";
return;
}
while (b !== 0) {
let temp = b;
b = a % b;
a = temp;
}
document.getElementById("hcfResult").innerText = `HCF is ${a}`;
}
function generateTable() {
let num = parseInt(document.getElementById("tableNum").value);
let output = "";
if (isNaN(num)) {
document.getElementById("tableResult").innerText = "Enter a valid number.";
return;
}
for (let i = 1; i <= 10; i++) {
output += `${num} × ${i} = ${num * i}<br>`;
}
document.getElementById("tableResult").innerHTML = output;
}
</script>
</body>
</html>