-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
144 lines (139 loc) · 4.98 KB
/
index.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<html lang="en">
<head>
<title>calC</title>
<link rel="stylesheet" href="./main.css" />
</head>
<body>
<h1 id="our-title" class="calc-title text-center">Calculator</h1>
<hr />
<!-- div element is used to make divisions in html page, this makes it easy to style and make html element -->
<div class="calc-wrapper text-center">
<input type="text" id="input_field" disabled class="input-control" placeholder="Enter equation" />
<div class="result">
<p>RESULT</p>
</div>
<hr>
<table class="c-table">
<!-- First row of calculator buttons -->
<tr class="c-row">
<td class="c-cell c-number-color" onclick="appendToInputField(7)">
<div class="c-btn">
<span>7</span>
</div>
</td>
<td class="c-cell c-number-color" onclick="appendToInputField(8)">
<div class="c-btn">
<span>8</span>
</div>
</td>
<td class="c-cell c-number-color" onclick="appendToInputField(9)">
<div class="c-btn">
<span>9</span>
</div>
</td>
<td class="c-cell c-symbol-color" onclick="appendToInputField(/)">
<div class="c-btn">
<span>/</span>
</div>
</td>
</tr>
<!-- Second row of calculator buttons -->
<tr class="c-row">
<td class="c-cell c-number-color" onclick="appendToInputField(4)">
<div class="c-btn">
<span>4</span>
</div>
</td>
<td class="c-cell c-number-color" onclick="appendToInputField(5)">
<div class="c-btn">
<span>5</span>
</div>
</td>
<td class="c-cell c-number-color" onclick="appendToInputField(6)">
<div class="c-btn">
<span>6</span>
</div>
</td>
<td class="c-cell c-symbol-color">
<div class="c-btn">
<span>×</span>
</div>
</td>
</tr>
<!-- Third row of calculator buttons -->
<tr class="c-row">
<td class="c-cell c-number-color" onclick="appendToInputField(1)">
<div class="c-btn">
<span>1</span>
</div>
</td>
<td class="c-cell c-number-color" onclick="appendToInputField(2)">
<div class="c-btn">
<span>2</span>
</div>
</td>
<td class="c-cell c-number-color" onclick="appendToInputField(3)">
<div class="c-btn">
<span>3</span>
</div>
</td>
<td class="c-cell c-symbol-color">
<div class="c-btn">
<span>-</span>
</div>
</td>
</tr>
<!-- Fourth row of calculator buttons -->
<tr class="c-row">
<td class="c-cell c-decimal-color" onclick="appendToInputField(.)">
<div class="c-btn">
<span>.</span>
</div>
</td>
<td class="c-cell c-number-color" onclick="appendToInputField(0)">
<div class="c-btn">
<span>0</span>
</div>
</td>
<td class="c-cell c-cell-equal">
<div class="c-btn">
<span>=</span>
</div>
</td>
<td class="c-cell c-symbol-color">
<div class="c-btn">
<span>+</span>
</div>
</td>
</tr>
</table>
<table class="c-table" >
<!-- Fifth row of calculator buttons -->
<tr class="c-row ">
<td class="c-cell c-cell-color" onclick="clearInputField()">
<div class="c-btn ">
<span>AC</span>
</div>
</td>
</tr>
</table>
</div>
<div></div>
</body>
<script>
function appendToInputField(n) {
console.log('The number is: ', n);
// Select DOM element using it's ID
const inputField = document.getElementById('input_field');
// Save the previous value of the input field in the a temp variable
const fieldValue = inputField.value;
// The new value of the input field is previous value + new n
inputField.value = fieldValue + n;
}
function clearInputField() {
document.getElementById('input_field').value='';
}
</script>
/
</html>