Skip to content

Instantly share code, notes, and snippets.

@thenanosoft
Created March 2, 2022 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thenanosoft/468048ec96e8f32b82437e3fbcbcca1a to your computer and use it in GitHub Desktop.
Save thenanosoft/468048ec96e8f32b82437e3fbcbcca1a to your computer and use it in GitHub Desktop.
Create calculator calling different operators with functions in javascript
// Create calculator calling different operators with functions in javascript
function pow(value0, value1) {
return Math.pow(value0, value1);
}
function mod(value0, value1) {
return value0 % value1;
}
function div(value0, value1) {
return value0 / value1;
}
function mul(value0, value1) {
return value0 * value1;
}
function add(value0, value1) {
return value0 + value1;
}
function subtract(value0, value1) {
return value0 - value1;
}
function calculator(value0, value1, operator) {
return operator(value0, value1);
}
console.log(calculator(2,5,mod));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment