check if number between two numbers javascript code example

Example 1: random int between two numbers javascript

// Between any two numbers
Math.floor(Math.random() * (max - min + 1)) + min;

// Between 0 and max
Math.floor(Math.random() * (max + 1));

// Between 1 and max
Math.floor(Math.random() * max) + 1;

Example 2: 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 3: if between two numbers javascript

if (500 < thenumber && thenumber < 600) {
  // ...
}

Tags:

C Example