-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator.html
More file actions
128 lines (113 loc) · 4.4 KB
/
calculator.html
File metadata and controls
128 lines (113 loc) · 4.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Calculator</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 700px;
background-color: rgb(186, 180, 180);
}
#calculator {
width: 280px;
color: black;
box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
padding: 20px;
border-radius: 10px;
background-color: rgba(73, 73, 72, 0.758);
}
.button-row {
display: flex;
justify-content: space-between;
margin: 5px 0;
}
button {
background-color: white;
color: black;
border-radius: 5px;
height: 60px;
width: 60px;
border: 1px solid rgb(237, 236, 232);
margin: 5px;
font-size: 18px;
cursor: pointer;
}
#equals-button {
background-color: orange;
color: black;
font-weight: bold;
}
#results {
width: 100%;
margin-bottom: 10px;
font-size: 28px;
background-color: whitesmoke;
padding: 5px;
text-align: right;
border-radius: 5px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<div id="calculator">
<input type='text' disabled id="results"/>
<div class = "button-row">
<button onclick="backspace()">C</button>
<button onclick="clearResults()">B</button>
<button onclick="squareNumber()">x^2</button>
<button onclick="appendToResults('%')">%</button>
</div>
<div class = "button-row">
<button onclick="appendToResults('7')">7</button>
<button onclick="appendToResults('8')">8</button>
<button onclick="appendToResults('9')">9</button>
<button onclick="appendToResults('*')">X</button>
</div>
<div class = "button-row">
<button onclick="appendToResults('4')">4</button>
<button onclick="appendToResults('5')">5</button>
<button onclick="appendToResults('6')">6</button>
<button onclick="appendToResults('-')">-</button>
</div>
<div class = "button-row">
<button onclick="appendToResults('1')">1</button>
<button onclick="appendToResults('2')" >2</button>
<button onclick="appendToResults('3')">3</button>
<button onclick="appendToResults('+')">+</button>
</div>
<div class = "button-row">
<button onclick="appendToResults('.')">.</button>
<button onclick="appendToResults('0')">0</button>
<button onclick="appendToResults('/')">/</button>
<button id ="equals-button" onclick="calculaterResults()">=</button>
</div>
<script>
function appendToResults(value)
{
const display=document.getElementById('results');
display.value = display.value +=value; //it will add value with before number... 123
}
function backspace(){
const display = document.getElementById('results');
display.value = display.value.slice(0,-1);
}
function clearResults(){
const display = document.getElementById('results');
display.value = '';
}
function calculaterResults(){
const display = document.getElementById('results');
display.value = eval(display.value);
}
function squareNumber() {
const display = document.getElementById('results');
display.value = Math.pow(eval(display.value), 2);
}
</script>
</div>
</body>
</html>