Created
May 10, 2019 12:20
-
-
Save charleslukes/71d74e63f0063d826d675d262c8ada51 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