-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalculator.html
120 lines (103 loc) · 3.27 KB
/
calculator.html
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
<!DOCTYPE html>
<html>
<head>
<title>Simple Calculator</title>
<style>
body {
background-color: #f2f2f2;
/* Set the background color */
font-family: Arial, sans-serif;
/* Change the font family */
}
h1 {
color: #333333;
/* Change the heading color */
text-align: center;
}
form {
background-color: #ffffff;
/* Set the background color of the form */
padding: 20px;
border-radius: 5px;
/* Add some border-radius for rounded corners */
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
/* Add a subtle box shadow */
width: 300px;
/* Adjust the width of the calculator */
margin: 0 auto;
/* Center the calculator horizontally */
}
label {
display: inline-block;
width: 100px;
}
input[type="number"],
select {
width: 150px;
/* Adjust the input/select width */
padding: 5px;
border-radius: 3px;
border: 1px solid #cccccc;
}
input[type="button"] {
background-color: #4caf50;
/* Set the button background color */
color: #ffffff;
/* Set the button text color */
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
margin-top: 10px;
}
input[type="button"]:hover {
background-color: #45a049;
/* Change the button background color on hover */
}
.result {
font-weight: bold;
margin-top: 10px;
}
</style>
<script>
// JavaScript code remains the same
</script>
</head>
<body>
<h1>Simple Calculator</h1>
<form>
<label for="num1">Number 1:</label>
<input type="number" id="num1" name="num1"><br><br>
<label for="operator">Operator:</label>
<select id="operator" name="operator">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select><br><br>
<label for="num2">Number 2:</label>
<input type="number" id="num2" name="num2"><br><br>
<input type="button" value="Calculate" onclick="calculate()"><br><br>
<div class="result" id="result"></div>
</form>
<script>
function calculate() {
var num1 = parseFloat(document.getElementById("num1").value);
var num2 = parseFloat(document.getElementById("num2").value);
var operator = document.getElementById("operator").value;
var result;
if (operator == "+") {
result = num1 + num2;
} else if (operator == "-") {
result = num1 - num2;
} else if (operator == "*") {
result = num1 * num2;
} else if (operator == "/") {
result = num1 / num2;
}
document.getElementById("result").innerText = "The result is: " + result;
}
</script>
</body>
</html>