Skip to content

Commit 2872e88

Browse files
authored
Add files via upload
1 parent e17a670 commit 2872e88

3 files changed

Lines changed: 151 additions & 0 deletions

File tree

index.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Calculator</title>
5+
<link rel="stylesheet" href="style.css" />
6+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
7+
<script src="script.js"></script>
8+
</head>
9+
<body>
10+
<div id="calculator">
11+
<div id="total">
12+
</div>
13+
<div id="operators">
14+
<a>+</a>
15+
<a>-</a>
16+
<a>/</a>
17+
<a>*</a>
18+
<a id="equals">=</a>
19+
</div>
20+
<div id="numbers">
21+
<a>1</a>
22+
<a>2</a>
23+
<a>3</a>
24+
<a>4</a>
25+
<a>5</a>
26+
<a>6</a>
27+
<a>7</a>
28+
<a>8</a>
29+
<a>9</a>
30+
<a id="clear">C</a>
31+
<a>0</a>
32+
<a id="clearall">AC</a>
33+
</div>
34+
</div>
35+
</body>
36+
</html>

script.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
$(document).ready(function(){
2+
var testNumLength = function(number) {
3+
if (number.length > 9) {
4+
totaldiv.text(number.substr(number.length-9,9));
5+
if (number.length > 15) {
6+
number = "";
7+
totaldiv.text("Err");
8+
}
9+
}
10+
};
11+
var number = "";
12+
var newnumber = "";
13+
var operator = "";
14+
var totaldiv = $("#total");
15+
totaldiv.text("0");
16+
$("#numbers a").not("#clear,#clearall").click(function(){
17+
number += $(this).text();
18+
totaldiv.text(number);
19+
testNumLength(number);
20+
});
21+
$("#operators a").not("#equals").click(function(){
22+
operator = $(this).text();
23+
newnumber = number;
24+
number = "";
25+
totaldiv.text("0");
26+
});
27+
$("#clear,#clearall").click(function(){
28+
number = "";
29+
totaldiv.text("0");
30+
if ($(this).attr("id") === "clearall") {
31+
newnumber = "";
32+
}
33+
});
34+
//Add your last .click() here!
35+
$("#equals").click(function(){
36+
if (operator === "+"){
37+
number = (parseInt(number, 10) + parseInt(newnumber,10)).toString(10);
38+
} else if (operator === "-"){
39+
number = (parseInt(newnumber, 10) - parseInt(number,10)).toString(10);
40+
} else if (operator === "/"){
41+
number = (parseInt(newnumber, 10) / parseInt(number,10)).toString(10);
42+
} else if (operator === "*"){
43+
number = (parseInt(newnumber, 10) * parseInt(number,10)).toString(10);
44+
}
45+
totaldiv.text(number);
46+
testNumLength(number);
47+
number = "";
48+
newnumber = "";
49+
});
50+
});

style.css

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
body, div, a {
2+
padding:0;
3+
margin:0;
4+
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
5+
}
6+
7+
#calculator {
8+
background-color: #999;
9+
width: 310px;
10+
height: 460px;
11+
border: 3px black solid;
12+
margin: 10px auto;
13+
padding: 5px;
14+
-moz-border-radius: 10px;
15+
-webkit-border-radius: 10px;
16+
-khtml-border-radius: 10px;
17+
border-radius: 10px;
18+
}
19+
20+
#calculator a {
21+
display: block;
22+
float: left;
23+
cursor: pointer;
24+
text-decoration: none;
25+
text-align: center;
26+
background: -moz-linear-gradient(top, #EDEDED, #DCDCDC);
27+
background: -webkit-gradient(linear, left top, left bottom, from(#EDEDED), to(#DCDCDC));
28+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#EDEDED', endColorstr='#DCDCDC');
29+
-moz-border-radius: 10px;
30+
-webkit-border-radius: 10px;
31+
-khtml-border-radius: 10px;
32+
border-radius: 10px;
33+
color: black;
34+
}
35+
36+
#numbers, #operators {
37+
margin: auto;
38+
}
39+
40+
#operators a {
41+
width: 45px;
42+
height: 45px;
43+
font-size: 39px;
44+
padding: 2px;
45+
margin: 5px 6px;
46+
}
47+
48+
#numbers a {
49+
width: 50px;
50+
height: 50px;
51+
font-size: 32px;
52+
padding: 10px;
53+
margin: 5px 15px;
54+
}
55+
56+
#total {
57+
height: 70px;
58+
width: 300px;
59+
margin:auto;
60+
background-color:white;
61+
margin-bottom: 5px;
62+
text-align: right;
63+
font-size: 60px;
64+
padding: 0px 5px;
65+
}}

0 commit comments

Comments
 (0)