diff --git a/index.js b/index.js index 3bb4d07..4ed82da 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,26 @@ * 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 result = 0 + if(process.argv[2] == "plus" & process.argv.length > 3){ + for(let x = 3; x < process.argv.length; x++){ + result += parseInt(process.argv[x]); + } + return result; + }else if(process.argv[2] == "minus" & process.argv.length > 3){ + result = parseInt(process.argv[3]) + for(let x = 4; x < process.argv.length; x++){ + result -= parseInt(process.argv[x]); + } + return result; + }else if(process.argv.length == 2){ + return `No operation provided...`; + }else if(process.argv.length < 4){ + return `No numbers provided...`; + }else{ + return `Invalid operation: ${process.argv[2]}`; + } +} // Don't change anything below this line. module.exports = calculator;