<html>
<head>
<script lang="javascript">
var arr=new Array();
var no=1,counter=0,sec=0;
function calc1()
{
if(no%10 == 0 && no<=1000000)
{
arr[counter]=no;
counter++;
}
no+=1;
sec++;
t=setTimeout("calc1()",1000);
if(sec==10)
{
f1.t1.value=counter + " Number Found";
}
}
function calc()
{
var no=0,counter=0;
var diff=0;
d=new Date();
startsec=d.getSeconds();
currentsec=startsec;
while( diff < 1)
{
if(no%10 == 0 && no<=1000000)
{
arr[counter]=no;
counter++;
}
no++;
//**********calculation of time*********
f1.t1.value=counter + " Number Found";
d=new Date();
currentsec=d.getSeconds();
if(currentsec<startsec)
currentsec=60+currentsec;
diff=currentsec-startsec;
//********************
}
}
function starttimer()
{
d=new Date();
f1.sec.value=d.getSeconds();
t=setTimeout("starttimer()",1000);
}
function stoptimer()
{
clearTimeout(t);
display();
}
function display()
{
var str="";
for(var i in arr)
{
str=str+arr[i]+" | ";
}
document.getElementById("msg").innerHTML=str;
}
</script>
</head>
<body onload="starttimer()">
<h3>PROGRAM 4 : </h3><h4>FINDING MULTIPLES OF 10</h4><BR>
<form name="f1">
<input type="text" id="t1" name="t1"/>
<input type="text" id="sec" name="sec"/>
<input type="button" name="b1" value="START (According to Time)" onclick="calc()"/>
<input type="button" name="b1" value="START (According to Timeout)" onclick="calc1()"/>
<input type="button" name="b2" value="SHOW NUMBERS" onclick="stoptimer()"/>
<div id="msg"></div>
</form>
</body>
</html>
No comments:
Post a Comment