Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Created April 30, 2017 16:29
Show Gist options
  • Save gorkamu/d245706d3231bacadf2a19cb0f0ffb9a to your computer and use it in GitHub Desktop.
Save gorkamu/d245706d3231bacadf2a19cb0f0ffb9a to your computer and use it in GitHub Desktop.
Example of a simple calculator in js
'use strict'
var args = process.argv.slice(2);
var result = null;
if(args.length == 3){
var num1 = parseFloat(args[0]);
var operation = args[1];
var num2 = parseFloat(args[2]);
switch(operation){
case "+":
result = parseFloat(num1+num2);
break;
case "-":
result = parseFloat(num1-num2);
break;
case "*":
result = parseFloat(num1*num2);
break;
case "/":
result = parseFloat(num1/num2);
break;
}
}
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment