diff --git a/index.js b/index.js index 3bb4d07..d511b42 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,36 @@ * Depending on the operation, either add up all of the numbers or subtract all of the numbers, from left to right. * @returns {number} The result of either adding all numbers or subtracting all numbers, depending on the arguments added to the command line. */ -function calculator() {} +function calculator() { +let sum = 0; +let operator = process.argv[2]; +const argumentInfo = process.argv -// Don't change anything below this line. +if(process.argv.length <= 2){ + return "No operation provided..."; +}; +if(operator !== "plus" && operator !== "minus"){ + return `Invalid operation: ${operator}` +}; +if(process.argv.length === 3){ + return "No numbers provided..." +}; +if (operator === "plus"){ + for(let i = 3; i < argumentInfo.length; i++){ + let num = Number(argumentInfo[i]); + sum += num + }; +}; +if (operator === "minus"){ + for(let i = 3; i < argumentInfo.length; i++){ + let num = Number(argumentInfo[i]); + sum -= num + }; +}; +return sum; +} + +console.log(calculator()) + +// Don't change anything blow this line. module.exports = calculator;