0% found this document useful (0 votes)
2 views6 pages

JS

The document contains multiple HTML pages with JavaScript functions for basic arithmetic operations, calculating the area of a circle, finding the average of three numbers, determining the greater of two numbers, checking string length, multiplying a number by three, and identifying if a number is positive or negative. Each section includes user prompts and displays results using document.write or alerts. The examples demonstrate fundamental programming concepts in JavaScript for user interaction and calculations.

Uploaded by

naidu eden
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

JS

The document contains multiple HTML pages with JavaScript functions for basic arithmetic operations, calculating the area of a circle, finding the average of three numbers, determining the greater of two numbers, checking string length, multiplying a number by three, and identifying if a number is positive or negative. Each section includes user prompts and displays results using document.write or alerts. The examples demonstrate fundamental programming concepts in JavaScript for user interaction and calculations.

Uploaded by

naidu eden
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 6

<!

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>

<p id="input">Enter First Number: <input id="one">


<br/><br/>
Enter Second Number: <input id="two"></p>
<p><button onclick="fun()">Add, Subtract, Multiply, Divide</button></p>
<p id="res" style="display:none;">
Addition Result = <input id="add"><br/><br/>
Subtraction Result = <input id="subtract"><br/><br/>
Multiplication Result = <input id="multiply"><br/><br/>
Division Result = <input id="divide"></p>

</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>

ADD + SUB + MUL + DIV

<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;

// Get user input


n1 = parseInt(prompt("Enter first number:"));
n2 = parseInt(prompt("Enter second number:"));
n3 = parseInt(prompt("Enter third number:"));

avg = (n1 + n2 + n3) / 3;


alert("Average: " + avg);
</script>
</body>
</html>

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>

You might also like