Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Calculator for two numbers

const calculator = (a, b, operator) => {
  let resultNum = 0
    switch (operator) {
      case "add":
        resultNum = a + b;
        break;
      case "subtract":
        resultNum = a - b;
        break;
      case "multiply":
        resultNum = a * b;
        break;
      case "divide":
        resultNum = a / b;
        break;
      default:
        resultNum = 0;
    }
  return resultNum
}

// With love @kouqhar
Comment

PREVIOUS NEXT
Code Example
Javascript :: 20 most common question in javascript 
Javascript :: let result = 7 + 13 / 9 + 7; let result2 = 100 / 2 * 6; answer= result* result2; result = answer; final Result = result.toFixed(2); final Number = Number(final Result); console.log(finalNumber); 
Javascript :: dayofyear mongodb 
Javascript :: prisma multiple relation counts 
Javascript :: Joi conditional validation refer parent object 
Javascript :: An Array Of Functions With Parameter 
Javascript :: square brackets javascript object key 
Javascript :: NG0100: Expression has changed after it was checked 
Javascript :: javascrit loop array 
Javascript :: how to check bot channel permissions 
Javascript :: Control a progress bar for custom video player 
Javascript :: js filter out html 
Javascript :: sort items 
Javascript :: JavaScript is synchronous by default 
Javascript :: how to close bootstrap modal after save 
Javascript :: how to change array elements position in array in javascript 
Javascript :: Initialize View With Collection Backbone 
Javascript :: how to delete array filter in react hooks 
Javascript :: javascript get max value in array of objects 
Javascript :: jquery if element has multiple classes 
Javascript :: hello world js 
Javascript :: react how to get checkbox value on click 
Javascript :: looping object 
Javascript :: = meaning in javascript 
Javascript :: run function periodically with setInterval 
Javascript :: the document object 
Javascript :: JavaScript Constructor Function Parameters 
Javascript :: creating js classes 
Javascript :: JavaScript Validation API 
Javascript :: pizza form validation jquery 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =