For Loop Programs – JavaScript

For Loop Programs JavaScript

Table of Contents

Add all digits in a Number

10

				
					<script type="litespeed/javascript">a="1234";g=a;b=a.length;d=0;for(i=1;i<=b;i++){c=a%10;a=Math.floor(a/10);d=d+c}
document.write(d)</script>
				
			

Armstrong

armstrong

				
					<script type="litespeed/javascript">a="153";g=a;b=a.length;d=0;for(i=1;i<=b;i++){c=a%10;a=Math.floor(a/10);d=d+(c*c*c)}
if(g==d){document.write("armstrong")}else{document.write(" not armstrong")}</script>
				
			

Break

2

4

6

				
					<script type="litespeed/javascript">var a=2;for(i=1;i<10;i++){document.write(a*i+"<br>");if(i==3){break}}</script>
				
			

Reverse a Number

4321

				
					<script type="litespeed/javascript">a="1234";g=a;b=a.length;d=0;for(i=1;i<=b;i++){c=a%10;a=Math.floor(a/10);d=d*10+c}
document.write(d)</script>
				
			

Take Your Free Live Demo Class Now

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Send You the Course Fees Details In Below Number

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

We Will Call Back You Shortly

Enter Your DETAILS BELOW

Enter Your DETAILS BELOW TO take

free demo class