Skip to content

Instantly share code, notes, and snippets.

@anushshukla
Created July 11, 2019 06:11
Show Gist options
  • Select an option

  • Save anushshukla/b339420bcd132daa3848ca1473f1e8c5 to your computer and use it in GitHub Desktop.

Select an option

Save anushshukla/b339420bcd132daa3848ca1473f1e8c5 to your computer and use it in GitHub Desktop.
NodeJs Script for a Basic Calculator
const add = function(input1, input2) {
return input1 + input2;
}
const subtract = function(input1, input2) {
return input1 - input2;
}
const multiple = function(input1, input2) {
return input1 * input2;
}
const divide = function(input1, input2) {
return input1 / input2;
}
const compute = function(input1, operator, input2) {
switch(operator) {
case "+": return add(input1, input2);
case "-": return subtract(input1, input2);
case "*": return multiple(input1, input2);
case "/": return divide(input1, input2);
}
}
export default compute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment