From e513a67b9555cdc4eaf05d60732c62e0b4a87786 Mon Sep 17 00:00:00 2001 From: David Higgins Date: Thu, 8 May 2014 18:17:33 -0400 Subject: [PATCH] added clear function, resolves #1 --- index.html | 14 ++++++++++++-- jquery.calc.js | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index f851ea2..e1f069e 100644 --- a/index.html +++ b/index.html @@ -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; + } @@ -34,11 +38,17 @@

jQuery Calculator

-
+
+
+ Clr +
+
+
0
+
7
8
diff --git a/jquery.calc.js b/jquery.calc.js index 78bdd05..22634d6 100644 --- a/jquery.calc.js +++ b/jquery.calc.js @@ -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); @@ -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);