-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
57 lines (51 loc) · 1.53 KB
/
index.html
File metadata and controls
57 lines (51 loc) · 1.53 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Multiplication calculator</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div class="container">
<h1>Multiplication Calculator</h1>
<label for="num1">Enter first number:</label><br />
<input
type="text"
id="num1"
placeholder="First number"
required
/><br /><br />
<label for="num2">Enter second number:</label><br />
<input
type="text"
id="num2"
placeholder="Second number"
required
/><br /><br />
<button type="button" id="calcBtn">Calculate</button>
<p id="result"></p>
</div>
<script>
let button = document.getElementById("calcBtn");
button.addEventListener("click", () => {
let num1 = document.getElementById("num1").value;
let num2 = document.getElementById("num2").value;
// Check if inputs are valid numbers
if (
isNaN(num1) ||
isNaN(num2) ||
num1.trim() === "" ||
num2.trim() === ""
) {
alert("Please enter valid numbers!");
} else {
let product = Number(num1) * Number(num2);
document.getElementById(
"result"
).innerText = `The result of ${num1} × ${num2} = ${product}`;
}
});
</script>
</body>
</html>