Scripting in HTML

1) Basic Program

<html>

<head>

<title> My first Js program</title></head>

<body>

<center>

<script type=”text/javascript”>

document.write(“Welcome to the browser using Js”;)

</center>

</body>

</html>

2) Addition

<html><head><title> Add with Js</title></head>

<body>

<center>

<script type=”text/javascript”>

var a,b,c; var string;

a=2; b=3; c=a+b;

string = “the result=”;

document.write(“Addition result”+”<br>”);

document.write(c);

</script>

3) Subtraction

<html><head><title> Subtract with Js</title></head>

<body>

<center>

<script type=”text/javascript”>

var a,b,c; var string;

a=3; b=3; c=a-b;

string = “the result=”;

document.write(“Subtraction result”+”<br>”);

document.write(c);

</script>

4) Largest Number

<html><head><title> Finding Largest Number</title></head>

<body>

<center>

<script type=”text/javascript”>

var a,b,c;

a=10; b=20;c=30;

if(a>b)

{if(a>c){document.write(“<h1> a is the largest number</h1>;

else

{document.write(“<h2> c is the largest number </h2>”);}}

else

{if (b>0)

{document.write(“<h2> b is the largest number </h2>”);}

Else

{document.write(“<h2> c is the largest number </h2>”);}}

</script>

</body>

</html>

5) Table of Squared numbers

<html>

<head><title> Squaring Numbers</title></head>

<body>

<table border=1 align=”center”>

<th> Number </th> <th> Square </th>

<script type=”text/javascript”>

var i=1;

while(i<=10)

{document.write(“<tr><td>” +i+”</td><td>” + (i*i) + “</td> </tr>”);

i++;}

</script>

</body>

</html>

6) Table of Squared numbers with For Loop

<html>

<head><title> Squaring Numbers with For Loop</title></head>

<body>

<table border=1 align=”center”>

<th> Number </th> <th> Square </th>

<script type=”text/javascript”>

var i;

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

{document.write(“<tr><td>” +i+”</td><td>” + (i*i) + “</td> </tr>”);}

</script>

</body>

</html>

7) Switch Case Js scripting in HTML

<html>

<head><title> Using Switch in Js </title></head>

<body>

<script type= “text/javascript”>

D = new Data();

Ch = d.getDays();

Switch(ch)

{

case 1: document.write(“Sunday”);

break;

case 2: document.write(“Monday”);

break;

case 3: document.write(“Tuesday”);

break;

case 4: document.write(“Wednesday”);

break;

case 5: document.write(“Thursday”);

break;

case 6: document.write(“Friday”);

break;

case 7: document.write(“Saturday”);

break;}

</script></body></html>

8) Array

<html>

<head><title> arrays </title></head>

<body>

<script type= “text/javascript”>

A = new Array(5);

for(i=0; i<5; i++)

{ A[i] = i;

document.write(‘another way of initialization’);

b = new Array(22, 43, 56, 74, 84);

for(i=0;i<5;i++)

{

document.write(b[i] + “<br>”);

}

document.write(“yet another way of initialization”);

var c= new Array(8, 16, 24, 32, 40);

for(i<0;i<5;i++) {

document.write(c[i]); }

document.write(“finish”);

</script>

</body>

</html>