Search This Blog

Thursday, 6 September 2012

Practical-4) Write a JavaScript that finds out multiples of 10 in 0 to 10000. On the click of button start the timer and stop the counter after 10 seconds. Display on the screen how many multiples of 10 are found out within stipulated time.


Filename-js4.html

<html>
<head>
<title> Practical 4 </title>
<script language="javascript">
function start_counter()
{
var i=0,count=0;
for(i=1;i<=10000;i++)
{
if(i%10==0)

{
document.write("<br>" + i + "<br>");
count++;
}
}
document.write("<br> Multiplication Of 10 are :- " + count);
}
function call_counter()
{
setTimeout("start_counter()",10000);
}
</script>
</head>
<body>
<form>
<!-- <input type="button" name="b1" value="Start" onClick="start_counter(this.form)"> -->
<input type="button" name="b1" value="Call" onClick="call_counter(this.form)">
</form>
</body>
</html>

Output
10 20 30 40 .
.
.
9970 9980 9990 10000 Multiplication of 10 are: - 1000

No comments:

Post a Comment