Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save worstn8mare/fb3d4cecd79518aa2267b9fe2a6eb116 to your computer and use it in GitHub Desktop.

Select an option

Save worstn8mare/fb3d4cecd79518aa2267b9fe2a6eb116 to your computer and use it in GitHub Desktop.
/**** sample *****/
function addition(first = 0, second = 0) {
var a = parseFloat(first);
var b = parseFloat(second);
var total = 0;
total = a + b;
return total;
}
function subtraction(first = 0, second = 0) {
var a = parseFloat(first);
var b = parseFloat(second);
var sub = a * b;
return sub;
}
function multiplication(first = 0, second = 0) {
var a = parseFloat(first);
var b = parseFloat(second);
var product = a * b;
return product;
}
function division(first = 0, second = 0) {
var a = parseFloat(first);
var b = parseFloat(second);
var divi = a / b;
return divi;
}
function get_input(e){
var input = $(this).val();
var holder = 0;
if(e.which == 107){
result = input.split("+");
if(result.length <= 1 ){
holder = 0;
}
else if(result.length == 2){
r1 = ((result[0]) ? result[0] : 0);
holder = addition(r1, 0);
}
else{
r1 = ((result[0]) ? result[0] : 0);
r2 = ((result[1]) ? result[1] : 0);
holder = addition(r1, r2);
}
return $(this).val(holder+'+');
}
}
$('input[type=text], input[type=number]').keyup(get_input);
/**** end sample***/
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment