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

Sample Javascript Programs

The document contains multiple HTML snippets demonstrating various JavaScript functionalities. These include basic arithmetic operations, comparisons between numbers, calculating the area of a circle, and looping through numbers to display even numbers. Each snippet is structured with input prompts and alerts to interact with the user.

Uploaded by

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

Sample Javascript Programs

The document contains multiple HTML snippets demonstrating various JavaScript functionalities. These include basic arithmetic operations, comparisons between numbers, calculating the area of a circle, and looping through numbers to display even numbers. Each snippet is structured with input prompts and alerts to interact with the user.

Uploaded by

mutindaamos540
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.

0 Transitional//EN"
"[Link]

<html xmlns="[Link]

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Javascript</title>

<script type="text/javascript">

function add()

var a,b,sum;

a=parseInt([Link]("first").value);

b=parseInt([Link]("second").value);

sum=a+b;

[Link]("answer").value=sum;

</script>

</head>

<body>

<p>FIRST NUMBER:<input id="first" /></p>

<p>SECOND NUMBER:<input id="second" /></p>

<p><button onclick="add()">CALCULATE</button></p>

<p><input id="answer" /></p>

</body>

</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"[Link]

<html xmlns="[Link]

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Javascript</title>

<script type="text/javascript">

const a=parseInt(prompt("enter value of a"));

const b=parseInt(prompt("enter value of b"));

if(a>b)

alert("A is Larger");

else

alert("B is Larger");

</script>

</head>

<body>

</body>

</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"[Link]

<html xmlns="[Link]

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Javascript</title>

<script type="text/javascript">

const a=parseInt(prompt("enter value of a"));


const b=parseInt(prompt("enter value of b"));

const c=parseInt(prompt("enter value of c"));

if(a>b && a>c)

alert("A is Larger");

else if(b>a && b>c)

alert("B is Larger");

else if(c>a && c>b)

alert("C is Larger");

else

alert("THEY ARE EQUAL");

</script>

</head>

<body>

</body>

</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"[Link]

<html xmlns="[Link]

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Javascript</title>

<script type="text/javascript">

let area;

k=3.142;

const r=parseInt(prompt("Enter the radius"));

area=k*r*r;

alert("AREA IF A CIRCLE IS"+area);

</script>

</head>

<body>

</body>

</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"[Link]

<html xmlns="[Link]

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Javascript</title>

<script type="text/javascript">

var i;

for(i=1;i<=10;i++)

if(i%2==0)

[Link](i+" <br>");

}
</script>

</head>

<body>

</body>

</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"[Link]

<html xmlns="[Link]

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Javascript</title>

<script type="text/javascript">

var i=1;

while(i<=10)

[Link](i+" <br>");

i++;

</script>

</head>

<body>

</body>

</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"[Link]
<html xmlns="[Link]

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Javascript</title>

<script type="text/javascript">

var i=1;

while(i<=10)

if(i%2==0)

[Link](i+" <br>");

i++;

</script>

</head>

<body>

</body>

</html>

You might also like