Loops in JavaScript
Free Web development courses with real-time projects Start Now!!
Program 1
<html> <head><title>Demo for Loops in JavaScript</title> <script langugage="javascript"> var i,n,j n=parseInt(prompt("Enter a limit")) for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { document.write("<center>") document.write("<font color=red size=8>") document.write("*") document.write("</font>") document.write("</center>") } } </script> </head> <body> </body> </html>
Program 2
<html> <head><title>Demo for Loops in JavaScript</title> <script langugage="javascript"> var n,r,s=0,m n=parseInt(prompt("Enter a number")) m=n document.write("<center>") document.write("<font color=blue size=5>") while(n!=0) { r=parseInt(n%10) r=parseInt(r) //s=s+r s=(s*10)+r n=parseInt(n/10) } if(m==s) document.write(" No is palindrom") else document.write(" No is not palindrom") // document.write("Reverse is: ") // document.write(s) document.write("</font>") document.write("</center>") </script> </head> <body> </body> </html>
Did we exceed your expectations?
If Yes, share your valuable feedback on Google