Created
May 10, 2019 12:19
-
-
Save charleslukes/6e18f7f7d57ff757f506010fc8027a79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A simple calculator project implementing the add numbers method | |
*/ | |
//Add method | |
function addNumber (...arg) { | |
let calculator = 0; | |
if(arg.length === 0){ | |
throw new Error('The input cannot be empty'); | |
} | |
for (let index = 0; index < arg.length; index++) { | |
if(typeof arg[index] !== 'number'){ | |
return 'Input must be a number'; | |
} | |
calculator += arg[index]; | |
} | |
return calculator; | |
} | |
module.exports = addNumber; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment