calculation using javascript code example
Example 1: calculate two number and diplay next field without reload the page javascript
var text1 = document.getElementById("Text1");
var text2 = document.getElementById("Text2");
function add_number() {
var first_number = parseFloat(text1.value);
if (isNaN(first_number)) first_number = 0;
var second_number = parseFloat(text2.value);
if (isNaN(second_number)) second_number = 0;
var result = first_number + second_number;
document.getElementById("txtresult").value = result;
}
Example 2: javascript Arithmetic operators
var additionOutput = 2 + 2;
var subtractionOutput = 2 - 2;
var multiplcationOutput = 2 * 2;
var divisionOutput = 2 / 2;
var exponentiation = 2**2;
var modulus = 5 % 2;
var unaryOperator = 1;
++unaryOperator;