Skip to content

Commit

Permalink
added clear function, resolves #1
Browse files Browse the repository at this point in the history
  • Loading branch information
zoul0813 committed May 8, 2014
1 parent 7a351b1 commit e513a67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 12 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
font-weight: bold;
font-size: 2em;
}
.result {
.result, .clear {
text-align: right;
font-weight: bold;
font-size: 2em;
}
.clear {
text-align: center;
cursor: pointer;
}
</style>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
Expand All @@ -34,11 +38,17 @@ <h1>jQuery Calculator</h1>
</header>
<div id="calculator">
<div class="row">
<div class="col-sm-12">
<div class="col-sm-2">
<div class="well clear">
Clr
</div>
</div>
<div class="col-sm-10">
<div class="well result">
0
</div>
</div>

<div class="digits">
<div class="col-xs-3"><div class="well digit">7</div></div>
<div class="col-xs-3"><div class="well digit">8</div></div>
Expand Down
8 changes: 8 additions & 0 deletions jquery.calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

jQuery(function($) {
var digits = $('#calculator .digits .digit');
var clear = $('#calculator .clear');
var calculator = { left: false, right: false, result: 0, operator: '+' };
function calculate() {
calculator.result = eval(calculator.left + calculator.operator + calculator.right);
Expand All @@ -30,6 +31,13 @@ jQuery(function($) {
var leftBuffer = '';
var rightBuffer = '';

clear.click(function() {
leftBuffer = '';
rightBuffer = '';
calculator = { left: false, right: false, result: 0, operator: '+' };
$('#calculator .result').text(calculator.result);
});

digits.click(function() {
var key = $(this).text();
console.log(leftBuffer, rightBuffer);
Expand Down

0 comments on commit e513a67

Please sign in to comment.