Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1K views

1.squares, Roots, Cubes, Complements Program Coding

The document contains 10 coding programs written in HTML and JavaScript that demonstrate different programming concepts: 1. The first program calculates and displays squares, square roots, cubes, and complements of numbers from 1 to 100. 2. The second program creates a basic calculator that can perform addition, subtraction, multiplication, and division operations. 3. The third program sorts an array of string elements in alphabetical order. 4. The remaining programs demonstrate additional concepts like hit counters, form validation, digital clocks, mouse events, frames, and a basic search engine.

Uploaded by

Vinoth M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

1.squares, Roots, Cubes, Complements Program Coding

The document contains 10 coding programs written in HTML and JavaScript that demonstrate different programming concepts: 1. The first program calculates and displays squares, square roots, cubes, and complements of numbers from 1 to 100. 2. The second program creates a basic calculator that can perform addition, subtraction, multiplication, and division operations. 3. The third program sorts an array of string elements in alphabetical order. 4. The remaining programs demonstrate additional concepts like hit counters, form validation, digital clocks, mouse events, frames, and a basic search engine.

Uploaded by

Vinoth M
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

1.

SQUARES, ROOTS, CUBES, COMPLEMENTS


PROGRAM CODING
<html>
<head>
<title>square, squareroots, cubes, complements</title>
<script language=JavaScript>
var i;
document.write(square+<br>);
for(i=1;i<=100;i++)
{
Document.write(<br>+i+<b>---square---</b>+(i*i)+<br>);
}
document.write(squareroots+<br>);
for(i=1;i<=100;i++)
{
Document.write(<br>+i+<b>---squareroots---</b>+Math.sqrt(i)+<br>);
}
document.write(cubes+<br>);
for(i=1;i<=100;i++)
{
Document.write(<br>+i+<b>---cubes---</b>+(i*i*i)+<br>);
}
document.write(complements+<br>);
for(i=1;i<=100;i++)
{
Document.write(<br>+i+<b>---complements---</b>+((-1)*i)+<br>);

}
</script>
</head>
</html>

2.CALCULATOR
PROGRAM CODING

<html>
<head>
<title>CALCULATOR</title>
<script language=JavaScript>
var istring= ;
function update(value)
{
istring+=value;
document.calc.input.value=istring;
}
</script>
</head>
<body>

<form name=calc>
<center><table border=4><tr><td>
<input type=text name=input maxlength=15 size=28><br>
<input type=button value=clear onclick=document.calc.input.value=istring=
;><br>
<input type=button value=mod onclick=update(%)><br>
<input type=button value=* onclick=update(*)><br>
<input type=button value=7 onclick=update(7)>
<input type=button value=8 onclick=update(8)>
<input type=button value=9 onclick=update(9)>
<input type=button value=/ onclick=update(/)><br>
<input type=button value=4 onclick=update(4)>
<input type=button value=5 onclick=update(5)>
<input type=button value=6 onclick=update(6)>
<input type=button value=- onclick=update(-)><br>
<input type=button value=1 onclick=update(1)>
<input type=button value=2 onclick=update(2)>
<input type=button value=3 onclick=update(3)>
<input type=button value=+ onclick=update(+)><br>
<input type=button value=0 onclick=update(0)>
<input type=button value=00 onclick=update(00)>
<input type=button value=. onclick=update(.)>
<input type=button value== onclick=input.value=eval(istring);>
</td></tr>
</table></center>
</form></body>
</html>

3.SORTING STRINGS
PROGRAM CODING
<html>
<head>
<title>sorting string</title>
<script language=JavaScript>
a=new Array();
n=prompt(enter array size);
for(i=0;i<n;i++)
{
a[i]prompt(enter array elements);
}
document.write(array elements are<br>);
for(i=0;i<n;i++)
{
document.write(<br>,a[i]);
}
a.sort();
document.write(<br>sorted array elements are<br>);
for(i=0;i<n;i++)
{
document.write(<br>,a[i]);
}
</script>
</head>
</html>

4.HIT COUNTER
PROGRAM CODING
<html>
<script language=JavaScript>
<!
functionnameDefined(ckie,nme)
{
var splitValues
var i
for(i=0;i<ckie.length;++i)
{
splitValues=ckie[i].split(=)
if (splitValues[0]==nme) return ture
}
return false
}
functiondelBlanks(strng)
{
var result=
var i
var chrn
for (i=0;i<strng.length;++i)
{
chrn=strng.charAt(i)
if (chrn!= ) result += chrn
}

return result
}
functiongetCookieValue(ckie,nme)
{
var splitValues
var i
for (i=0;i<strng.length;++i)
{
splitValues=ckie[i].split(=)
if(splitValues[0]==nme) return splitValues[1]
}
return
}
functioninsertCounter()
{
readCookie()
displayCounter()
}
functiondisplayCounter()
{
document.write(<H3 ALIGN=CENTER>)
document.write(Youve visited this page)
if(counter==1)document.write(the first time.)
elsedocument.write(counter+time.)
document.writeln(</H3>)
}

functionreadCookie()
{
var cookie = document.cookie
counter=0
var chkdCookie= delBlanks(cookie) //are on the client computer
var nvpair=chkdCookie.split(;)
if(nameDefined(nvpair,pageCount))
counter=parselnt(getCookieValue(nvpair,pageCount))
++counter
var futdate= new Date()
var expdate=futdate.getTime()
expdate +=3600000*24*30 //expires in 1 hour
futdate.setTime(expdate)
var newCookie=pageCount=+counter
newCookie +=;expires= + futdate.toGMTString()
window.document.cookies=newCookie
}
//
</script>
<body>
<script language=JavaScript>
<!
insertCounter()
//
</script>
</body>

</html>

5.EMAIL ID VALIDATION
PROGRAM CODING
<html>
<head>
<title>email address</title>
<body bgcolor=oofff>
<front size=18>
<center><b>e-mail address</b></center></front>
<script language=JavaScript>
function validate (from_id,email)
{
var reg=/^([A-Zs-z0-9_\-\.])+1@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address=document.froms[infrom].elements[email].value;
if (reg.test(address)==false)
{
alert(Invalid Email Address);
return false;
}
}
</script>
<form id=inform method=post

action=action.phponsubmit=JavaScript:return validate(inform,email);>
<input type=text id=email name=email/>
<input type=submit value=submit/>
</form>
</body>
</html>

6.SCROLL TEXT ON STATUS BAR


PROGRAM CODING
<html>
<head>
<center>scroll text on status bar</center>
<script language= JavaScript>
var count=0;
var delay=250;
var text=WELCOME TO CHENNAI;
function scroll()
{
window.status=text.substring(count,text.lenght)+text.substring(0,count)
if(count<text.lenght)
Count++;
else
count=0;
setTimeout(scroll(),delay);

}
</script>
</head>
<body onload=scroll();>
</body>
</html>

7.CHOICE LIST
PROGRAM CODING
<html>
<head>
<title>McDonals</title>
<script language=JavaScript>
var m;
function pick(F1)
{
var z= ;
for(j=0;j<3;j++)
{
for(i=0;i<F1.elements[j].length;i+++)
{
If(F1.elements[j][i].selected)

{
var y=F1.elements[j].options[i].value;
z=z+\n+y;
F1.elements[3].value=z;
}
}
}
m=z;
}
functionclr(F1)
{
F1.elements[3].value= ;
}
</script>
</head>
<body bgcolor=#00fff>
<h2><font color=blue size=20><center>Welcome to the world Famous Fast
Food center
</font><br>
<font color=red size=10>McDonalds!</center></font></h2>
<form name=F1>
<form size=+2>
Select the menu items of urchoice:</font><br><br>
<table>
<trvalign =top><td>
<font size=+1>
Major dishes:</font><br>

<select name=s1 MULTIPLE onBlur=pick(this.form)>


<option value=Mc burger->Rs.80 selected>mc burger
<option value=fish fullets->Rs.70 >fish fullets
<option value=burger->Rs.60>burger
<option value=veg burger->Rs.50>veg burger
</select>
<br><br>
</td><td>
<font size=+1>
Miscellaneous:</font><br>
</b><td>
</tr></table>
<font size=+1>
Stock:</font><br>
<select name=s2 MULTIPLE onBlur=pick(this.form)>
<option value=Dining Table & Chairs->500selected>Dining Table&Chairs
<option value=Tissues->1000>Tissues
<option value=Menu Cards->30>Menu Cards
<option value=Tool Bowl->50>Tool Bowl
</select>
<br><br></td>
</table>
<select name=s3 onBlur=pick(this.form)>
<option value=Milkshakes->Rs.35 selected>Milkshakes
<option value=Soft drinks->Rs.20 >Soft drinks
<option value=Softy->Rs.30>Softy

</select>
<br><br></td><td>
<th><font size=6>The items selected from the menu are:</font></th>
<table>
<trvalign=top><td>
<textarea name=TAI rows=10 cols=50>
</textarea><br<br></td>
<td><br>
<br><br>
<b>
<input type=button value=submit>
<input type=button value=clear onclick=clr(this.form)>
</form>
</body>
</html>

8.DIGITAL CLOCK
PROGRAM CODING
<html>
<head>
<title>DIGITAL CLOCK</title>
<script language=JavaScript>
functionnextone()
{
now=new Date();

hours=now.getHours();
mins=now.getMinutes();
sec=now.getSeconds();
if(mins<10)
time= +hours+:0+mins;
else
time= +hours+:+mins;
if(sec<10)
time+=:0+sec;
else
time+=:+sec;
document.timeform.timeclock.value=time;
setTimeout(nextone();4,100);
}
setTimeout(nextone();,100);
</script>
</head>
<body bgcolor =#00fff>
<font size=25><center>
Digital clock</font>
<form name=timeform>
<font size=8>
Current time=<input type=text name=timeclock size=10>
</font>
</form>
</body>

</html>

9.MOUSE EVENTS
PROGRAM CODING
<html>
<head>
<script language=JavaScript>
functionbigImg(x)
{
x.style.height=120px;
x.style.width=120px;
}
functionnormalImg(x)
{
x.style.height=32px;
x.style.width=32px;
}
</script>
</head>
<body>
<imgsrc=C:\User \Public \Pictures \Sample Pictures \Chrysanthemum.jpg
onmouseover=bigImg(this) onmouseout=normalImg(this)border=0
width=32 height=32>
</body>
</html>

10.FRAMES& SEARCH ENGINE


PROGRAM CODING
<html>
<head>
<title>VB Script frames</title>
</head>
<frameset cols=30%,70%>
<frame src=toc.html name=one>
<frame src=yah.html name=two>
</frameset>
</html>

<html>
<head>
<title>vbscript</title>
</head>
<script language=vbscript>
sub result(A)
if A=1 then
window.top.two.location.href=yah.html
end if
if A=2 then
window.top.two.location.href=inf.html
end if
end sub

if A=3 then
</script>
<body BGCOLOR=#00ffff>
<formname+A>
<div align=center>
<input type=radio name=choice onclick=result(1) checked>
yahoo_http://www.yahoo.com<br>
<input type=radio name=choice onclick=result(2)>
altavista_http://www.altavista.com<br>
<input type=radio name=choice onclick=result(3) >
infoseek_http://www.infoseek.com<br>
</div>
</from>
</body>
</html>

<html>
<head>
<title>yahoo</title>
</head>
<body bgcolor=#9991111>
<h1><center>yahoo page</center></h1>
</body>
</html>

<html>
<head>
<title>altavista</title>
</head>
<marquee>ALTAVISTA</marquee>
<body bgcolor=#9991111>
<h1><c>Altavista
</c></h1>
</body>
</html>

<html>
<head>
<title>infoseek</title>
</head>
<body bgcolor=#9991111>
<marquee>INFOSEEK PAGE</marquee>
<h1>infoseek page</h1>
</body>
</html>

You might also like