-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
155 lines (142 loc) · 6.04 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
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<title>Calculator</title>
<style type="text/css">
html,
body{
height: 100%;
}
.select_button{
margin: 5px;
}
.container{
padding: 20px;
margin: 0 auto;
background-color: #fff;
border-radius: 3px;
border:solid 1px;
border-color: grey;
font-weight: normal;
box-shadow: 10px 10px 5px grey;
}
</style>
</head>
<body>
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<br>
<section id="cover">
<div id="cover-caption">
<div id="container" class="container">
<div class="row">
<div class="col-sm-10 offset-sm-1 text-center">
<h1 class="display-3">Simple Calculator</h1>
<div class="info-form">
<form action="" class="form-inline justify-content-center" name="calc">
<input type="" name="" class="form-control col-sm-12" id="input_text" onkeyup="allowedChar(this);" >
<div class="col-sm-10 ">
<hr>
<div class="text-center select_button">
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('7')">7</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('8')">8</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('9')">9</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('/')">/</a>
</div>
<div class="text-center select_button">
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('4')">4</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('5')">5</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('6')">6</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('*')">x</a>
</div>
<div class="text-center select_button ">
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('1')">1</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('2')">2</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('3')">3</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('-')">-</a>
</div>
<div class="text-center select_button">
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('0')">0</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('.')">.</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('9')">9</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:addText('+')">+</a>
</div>
<div class="text-center select_button">
<a name="" class="btn btn-outline-primary col-sm-1" href="javascript:addText('(')">(</a>
<a name="" class="btn btn-outline-primary col-sm-1" href="javascript:addText(')')">)</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:removelastText()">DELETE</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:clearText()">CLEAR</a>
<a name="" class="btn btn-outline-primary col-sm-2" href="javascript:answerText()">=</a>
</div>
</div>
</form>
</div>
<br>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
<script type="text/javascript">
function addText(txt)
{
document.getElementById("input_text").value+=txt;
}
function clearText(txt)
{
document.getElementById("input_text").value="";
}
function removelastText()
{
var strng=document.getElementById("input_text").value;
document.getElementById("input_text").value=strng.substring(0,strng.length-1);
}
function answerText()
{
//easiest code "eval()"
try {
document.calc.input_text.value = eval(document.calc.input_text.value);;
} catch (e) {
if (e instanceof SyntaxError) {
alert(e.message);
}
}
// var a = parseInt("10");
// var b = parseInt("10");
// var c = a+b;
// var str = document.getElementById("input_text").value;
// var res = str.split("");
// document.getElementById("input_text").value = res;//display the splited value
// var temp = new Array();
// var temp = str.split("");
// for (a in temp ) {
// if (isNaN(temp[a]))
// {
// console.log (temp[a] = temp[a]);
// }
// else
// {
// console.log (temp[a] = parseInt(temp[a], 10));
// }
// }
}
//NUMBER ONLY
function allowedChar(elem) {
var validChars = /[0-9(). ]/;
var strIn = elem.value;
var strOut = '';
for(var i=0; i < strIn.length; i++) {
strOut += (validChars.test(strIn.charAt(i)))? strIn.charAt(i) : '';
}
elem.value = strOut;
}
</script>