Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 64 additions & 21 deletions calculator.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,108 @@

/**
* Declare a function named `calculatorModule`
* this function will have two private variables declared inside of it.
* @variable PRIVATE { Number } `memory`
* @variable PRIVATE { Number } `total`
* @return {object} `calculator` object that can be used
*/

function calculatorModule() {
var memory = 0;
var total = 0;
return calculator = {

/**
* sets the `total` to the number passed in
* @param { Number } x
* @return { Number } current total
*/


/**
load: (x) => {
if (typeof x === 'number') {
total = x;
return x;
} else {
throw new Error;
}
},
/**
* Return the value of `total`
* @return { Number }
*/


getTotal:() => {
return total;
},
/**
* Sums the value passed in with `total`
* @param { Number } x
*/

add: (x) => {
if (typeof x === 'number') {
total += x;
return total;
} else {
throw new Error;

}
},

/**
* Subtracts the value passed in from `total`
* @param { Number } x
*/

subtract: (x) => {
if (typeof x === 'number') {
total -= x;
} else {
throw new Error;
}
},

/**
* Multiplies the value by `total`
* @param { Number } x
*/


multiply: (x) => {
if (typeof x === 'number') {
total *= x;
} else {
throw new error;
}
},
/**
* Divides the value passing in by `total`
* @param { Number } x
*/


/**
*/
divide: (x) => {
if (typeof x === 'number') {
total /= x;
} else {
throw new error;
}
},
/**
* Return the value stored at `memory`
* @return { Number }
*/


/**
*/
recallMemory: () => {
return memory;
},
/**
* Stores the value of `total` to `memory`
*/


/**
saveMemory: () => {
memory = total;
},
/**
* Clear the value stored at `memory`
*/

/**
clearMemory: () => {
memory = 0;
},
/**
* Validation
*/

}
}
162 changes: 162 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.