addition in javascript code example

Example 1: how to do addition in javascript

//To add in Java script, you have to put an additon symbol '+' between them. If you have stored two numbers in variables, just put an addition symbol between the variable names.
//For example:
var a = 5
var b = 6
var c = a+b
var d = 5+6

Bot.send (c)/ print (c)// or whatever you use to get output
Bot.send (d)/ print (d)// or whatever you use to get output

//output will be: 11, 11

Example 2: add variable numerically in javascript

//use parseFloat(x); to change string to number
a=10;
b=20;
console.log(parseFloat(a)+parseFloat(b));//this will give a+b=30
//while
consle.log(a+b); //will give a+b=1020 [as String]

Example 3: javascript function to add two numbers

<!--Add two integer numbers using JavaScript.-->
<html>
	<head>
		<title>Add two integer numbers using JavaScript.</title>
		<script type="text/javascript">
			function addTwoNumbers(textBox1, textBox2){
				var x=document.getElementById(textBox1).value;
				var y=document.getElementById(textBox2).value;
				var sum=0;
				sum=Number(x)+Number(y);
				alert("SUM is: " + sum);
			}
		</script>
	</head>
<body>
	<h1>Add two integer numbers using JavaScript.</h1>
	<b>Enter first Number: </b><br>
	<input type="text" id="textIn1"/><br>
	<b>Enter second Number: </b><br>
	<input type="text" id="textIn2"/><br><br>
	<input type="button" id="btnSum" value="Calculate SUM" onClick="addTwoNumbers('textIn1','textIn2')"/>
</body>

</html>

Example 4: modulus js

console.log(10%3);
//returns 1 (the remainder of 10/3)