diff --git a/api/controller.js b/api/controller.js
index 949731c..a9efaf1 100644
--- a/api/controller.js
+++ b/api/controller.js
@@ -16,6 +16,7 @@ exports.calculate = function(req, res) {
'subtract': function(a, b) { return a - b },
'multiply': function(a, b) { return a * b },
'divide': function(a, b) { return a / b },
+ 'power': function(a, b) { return Math.pow(a, b) },
};
if (!req.query.operation) {
diff --git a/public/client.js b/public/client.js
index 1c60f86..1227a95 100644
--- a/public/client.js
+++ b/public/client.js
@@ -33,6 +33,9 @@ function calculate(operand1, operand2, operation) {
case '/':
uri += "?operation=divide";
break;
+ case '^':
+ uri += "?operation=power";
+ break;
default:
setError();
return;
diff --git a/public/default.css b/public/default.css
index c652a2b..59082df 100644
--- a/public/default.css
+++ b/public/default.css
@@ -41,12 +41,8 @@ BODY {
left: 0;
}
-#buttons {
- position: relative;
-}
-
#result {
- background-color: #9b9b9b;
+ background-color: skyblue; /* Hot Pink */
width: 226px;
height: 63px;
margin: 0;
@@ -59,18 +55,13 @@ BODY {
font-size: 25px;
text-align: right;
}
-
-/*BUTTON {
- background-color: #d5d5d5;
- border: 0;
- border-radius: 0;
- width: 55px;
- height: 42px;
- position: absolute;
-
- font-size: 22px;
-}*/
-
+.btn {
+ font-size: 1em;
+ height: 45px;
+ border: 1px solid black;
+ background-color: skyblue; /* Deep Pink */
+ margin: 4px;
+}
#sign,
#clear {
font-size: 17px;
@@ -92,53 +83,6 @@ BODY {
display: inline-block;
width: 25px;
height: 45px;
- background: url('digits.png') 0 0 no-repeat;
- background-size: cover;
- margin-top: 10px;
- font: 0/0 Arial;
- color: rgba(255, 255, 255, 0);
- text-indent: -9999px;
- z-index: 1;
-}
-
-.digit0 {
- background-position: 0 0;
-}
-
-.digit1 {
- background-position: -25px 0;
-}
-
-.digit2 {
- background-position: -50px 0;
-}
-
-.digit3 {
- background-position: -75px 0;
-}
-
-.digit4 {
- background-position: -100px 0;
-}
-
-.digit5 {
- background-position: -125px 0;
-}
-
-.digit6 {
- background-position: -150px 0;
-}
-
-.digit7 {
- background-position: -175px 0;
-}
-
-.digit8 {
- background-position: -200px 0;
-}
-
-.digit9 {
- background-position: -225px 0;
}
.resultchar.decimal {
@@ -176,11 +120,3 @@ BODY {
.calculator {
max-width: 320px;
}
-
-.btn {
- font-size: 1em;
- height: 45px;
- border: 1px solid black;
- background-color: #d5d5d5;
- margin: 4px;
-}
diff --git a/public/index.html b/public/index.html
index 400c454..1fd7a8d 100644
--- a/public/index.html
+++ b/public/index.html
@@ -41,6 +41,8 @@
+
+
diff --git a/test/arithmetic.test.js b/test/arithmetic.test.js
index deded48..bc3441c 100644
--- a/test/arithmetic.test.js
+++ b/test/arithmetic.test.js
@@ -94,6 +94,57 @@ describe('Arithmetic', function () {
});
// TODO: Challenge #1
+// add tests for subtraction
+ describe('Subtraction', function () {
+ it('subtracts two positive integers', function (done) {
+ request.get('/arithmetic?operation=subtract&operand1=42&operand2=21')
+ .expect(200)
+ .end(function (err, res) {
+ expect(res.body).to.eql({ result: 21 });
+ done();
+ });
+ });
+ it('subtracts a positive integer from zero', function (done) {
+ request.get('/arithmetic?operation=subtract&operand1=0&operand2=21')
+ .expect(200)
+ .end(function (err, res) {
+ expect(res.body).to.eql({ result: -21 });
+ done();
+ });
+ });
+ it('subtracts a negative integer from a positive integer', function (done) {
+ request.get('/arithmetic?operation=subtract&operand1=42&operand2=-21')
+ .expect(200)
+ .end(function (err, res) {
+ expect(res.body).to.eql({ result: 63 });
+ done();
+ });
+ });
+ it('subtracts two negative integers', function (done) {
+ request.get('/arithmetic?operation=subtract&operand1=-42&operand2=-21')
+ .expect(200)
+ .end(function (err, res) {
+ expect(res.body).to.eql({ result: -21 });
+ done();
+ });
+ });
+ it('subtracts two floating point numbers', function (done) {
+ request.get('/arithmetic?operation=subtract&operand1=42.5&operand2=21.5')
+ .expect(200)
+ .end(function (err, res) {
+ expect(res.body).to.eql({ result: 21 });
+ done();
+ });
+ });
+ it('subtracts with negative exponent', function (done) {
+ request.get('/arithmetic?operation=subtract&operand1=1.2e-5&operand2=-1.2e-5')
+ .expect(200)
+ .end(function (err, res) {
+ expect(res.body).to.eql({ result: 0.000024 });
+ done();
+ });
+ });
+ });
describe('Multiplication', function () {