JS
JS
doctype html>
<html>
<head>
<script>
var numOne, numTwo, res, temp;
function fun()
{
numOne = parseInt(document.getElementById("one").value);
numTwo = parseInt(document.getElementById("two").value);
if(numOne && numTwo)
{
temp = document.getElementById("res");
temp.style.display = "block";
res = numOne + numTwo;
document.getElementById("add").value = res;
res = numOne - numTwo;
document.getElementById("subtract").value = res;
res = numOne * numTwo;
document.getElementById("multiply").value = res;
res = numOne / numTwo;
document.getElementById("divide").value = res;
}
}
</script>
</head>
<body>
</body>
</html>
ADDITION OF TWO NUMBERS
<!doctype html>
<html>
<head>
<script>
function add()
{
var num1, num2, sum;
num1 = parseInt(document.getElementById("firstnumber").value);
num2 = parseInt(document.getElementById("secondnumber").value);
sum = num1 + num2;
document.getElementById("answer").value = sum;
}
</script>
</head>
<body>
<p>First Number: <input id="firstnumber"></p>
<p>Second Number: <input id="secondnumber"></p>
<button onclick="add()">Add Them</button>
<p>Sum = <input id="answer"></p>
</body>
</html>
<html>
<head>
<title>JS program to add, subtract, multiply, divide two numbers</title>
</head>
<body>
<script>
var n1, n2, s, d, m, q;
n1 = parseInt(prompt("Enter first number:"));
n2 = parseInt(prompt("Enter second number:"));
s = n1 + n2;
d = n2 - n1;
m = n1 * n2;
q = n1 / n2;
document.write("<br>Sum -" +s);
document.write("<br>Difference -" +d);
document.write("<br>Product -" +m);
document.write("<br>Division-" +q);
</script>
</body>
</html>
AREA OF A CIRCLE
<html>
<head>
<title>JS program to calculate area of circle</title>
</head>
<body>
<script>
var r, area;
r=parseInt(prompt("Enter radius of the circle:"));
area=3.14*r*r;
alert("Area - " + area);
</script>
</body>
</html>
AVERAGE OF 3 NUMBERS
<html>
<head>
<title>JS program to calculate average of three numbers</title>
</head>
<body>
<script>
// Declare the vairables
var n1, n2, n3, avg;
GREATER NUMBER
<!DOCTYPE html>
<html>
<head>
<title>sop1</title>
</head>
<body>
<h1> To accept two integers and display larger number of them </h1>
<script language=javascript>
var n1,n2
n1=prompt("Enter first number","type here")
n2=prompt("Enter second number","type here")
if(n1>n2)
document.write(n1+ " is the greater number")
else
document.write(n2+ " is the greater number")
</script>
</body>
</html>
LENGTH OF STRING
<!DOCTYPE html>
<html>
<head>
<title>sop3</title>
</head>
<body>
<h1> To check whether the length of string is 4 or greater </h1>
<script language=javascript>
var n
n=prompt("Enter any text")
if(n.length>=4)
document.write("Length of the string is greater than or equal to 4")
else
document.write("Length of the string is less than 4")
</script>
</body>
</html>
MULTIPLY WITH 3
<!DOCTYPE html>
<html>
<head>
<title>sop1</title>
</head>
<body>
<h1>To accept integer and display the result by multiplying it with 3</h1>
<script language=javascript>
var num,ans
num=prompt("Enter a number")
ans=num*3
document.write("Answer = "+ans)
</script>
</body>
</html>
POSITIVE OR NEGATIVE
<!DOCTYPE html>
<html>
<head>
<title>sop1</title>
</head>
<body>
<h1> To check whether user entered number is positive or negative </h1>
<script language=javascript>
var n
n=prompt("Enter a number","type here")
if(n>0)
document.write(n+ " is positive number")
else
document.write(n+ " is negative number")
</script>
</body>
</html>
UPPER OR LOWER CASE
<!DOCTYPE html>
<html>
<head>
<title>sop3</title>
</head>
<body>
<h1> To accept string and display it into lowercase and uppercase </h1>
<script language=javascript>
var n
n=prompt("Enter any text")
s1=n.toUpperCase()
s2=n.toLowerCase()
document.write("Uppercase of the string is "+s1 + "<br>")
document.write("Lowercase of the string is "+s2)
</script>
</body>
</html>