GTU WTAD 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

GTU WTAD 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.

 GTU WTAD Practical 4

Jump to GTU Practical 6

File Name : index.jsp

File Location : Tomcat_Apache\webapps\gtu04\

<html>
<head>
	<title> GTU WTAD 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 </title>
	<script type="text/javascript">
		var cnt=0;
		var result="";
		var rec="";
		var initial=0;

		function counter()
		{
			var dt=new Date();
			initial=dt.getTime();
			document.form1.time1.value=initial;

			while(cnt<=10000)
			{
				var dt1=new Date();
				currnt=dt1.getTime();

				if(currnt-initial>100)
					break;

				cnt++;
				if(cnt%10==0)
				{
					result+=cnt+"\n";
					rec+=currnt+"\n";
				}
			}
			document.form1.t1.value=result;
			document.form1.t2.value=rec;
		}
	</script>
</head>
<body>
	<center> <h2> GTU WTAD 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 </h2></center>
	
	<form name="form1">
		<input type="button" value="Start" name="start" onClick="counter()"><br>
		Start Time <input type="text" name="time1" readOnly>
		Multiplication <textarea name="t1" rows=10></textarea>
		Time in Milisecond <textarea name="t2" rows=10></textarea>
	</form>
</body>
</html>

 

Output

GTU WTAD Practical 4

 

Leave a Reply