From b822022fbd55afc1c0fddd78e515e7574ec5d4e9 Mon Sep 17 00:00:00 2001 From: Mika Dumont Date: Sun, 24 Dec 2017 14:45:51 -0800 Subject: [PATCH 1/2] calculator complete -1 --- calculator.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 6 deletions(-) diff --git a/calculator.js b/calculator.js index 3e5744c..064e5cb 100644 --- a/calculator.js +++ b/calculator.js @@ -5,6 +5,11 @@ * @variable PRIVATE { Number } `total` * @return {object} `calculator` object that can be used */ +var calculatorModule = function() { + var memory = 0; + var total = 0; +return { + /** @@ -12,54 +17,107 @@ * @param { Number } x * @return { Number } current total */ - - + + +load: function(num) { + if(typeof num === 'number') { + total = num; + return num; + } else { + return null; + } + }, + + /** * Return the value of `total` * @return { Number } */ + getTotal: function(){ + return total; + }, /** * Sums the value passed in with `total` * @param { Number } x */ - + add: (num) => { + if(typeof num === 'number') { + total = total + num; + return total; + } else { + return null; + } + }, /** * Subtracts the value passed in from `total` * @param { Number } x */ +subtract: (num) => { + if(typeof num === 'number') { + total = total - num; + return total; + } else { + return null; + } +}, /** * Multiplies the value by `total` * @param { Number } x */ - +multiply: (num) => { + if(typeof num === 'number') { + total = total * num; + return total; + } else { + return null; + } +}, /** * Divides the value passing in by `total` * @param { Number } x */ +divide: (num) => { + if(typeof num === 'number') { + total = total / num; + return total; + } else { + return null; + } +}, /** * Return the value stored at `memory` * @return { Number } */ +recallMemory: () => { + return memory; + +}, /** * Stores the value of `total` to `memory` */ - +saveMemory: () => { + return memory = total; +}, /** * Clear the value stored at `memory` */ +clearMemory: () => { + return memory = 0; +}, /** * Validation */ - +} +} From bb5fc989baef2f651be6dac17d99513d86f41070 Mon Sep 17 00:00:00 2001 From: Mika Dumont Date: Tue, 26 Dec 2017 17:30:29 -0800 Subject: [PATCH 2/2] calculator done --- calculator.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/calculator.js b/calculator.js index 064e5cb..ba15ae2 100644 --- a/calculator.js +++ b/calculator.js @@ -19,12 +19,12 @@ return { */ -load: function(num) { +load: (num) => { if(typeof num === 'number') { total = num; return num; } else { - return null; + throw new Error(); } }, @@ -33,7 +33,7 @@ load: function(num) { * Return the value of `total` * @return { Number } */ - getTotal: function(){ + getTotal: () => { return total; }, @@ -47,7 +47,7 @@ load: function(num) { total = total + num; return total; } else { - return null; + throw new Error(); } }, @@ -61,7 +61,7 @@ subtract: (num) => { total = total - num; return total; } else { - return null; + throw new Error(); } }, @@ -74,7 +74,7 @@ multiply: (num) => { total = total * num; return total; } else { - return null; + throw new Error(); } }, @@ -88,7 +88,7 @@ divide: (num) => { total = total / num; return total; } else { - return null; + throw new Error(); } },