Vous êtes sur la page 1sur 10

Write a Java Script to reverse a string entered by user. Name: Shobhit Bhardwaj Roll No.

: 7182

<html> <head> <title>reverse</title> <script type="text/JavaScript"> var str; str=prompt("Enter your string:"); var word; word=parseInt(word); word=1; var len=str.length; len=parseInt(len); len=str.length; for(var i=0;i<len;i++) if(str.charAt(i)==" ") word++; document.writeln("<br>Your entered string is="+str); document.writeln("<br>Your reversed string is="); var str1; str1=str.split(" "); for(var j=(word-1);j>=0;j--) document.writeln(str1[j]);

</script> </head> <body> </body> </html>

Write a script to print the following pattern * * * * * * * * * * * * * * Name: Shobhit Bhardwaj Roll No.: 7182

<html> <head> <title>pattern</title> <script type="text/JavaScript"> var i,j,k,n; alert("Enter the number:"); n=window.prompt(); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) if(j!=(n+1)/2) document.writeln("&nbsp&nbsp"); else

document.writeln("*"); document.writeln("<br>"); } for(i=(n+1)/2;i>=1;i--) { for(j=((n+1)/2-i);j>=1;j--) document.writeln("&nbsp","&nbsp"); for(k=((((n-1)/2)*i)-1);k>=1;k--) document.writeln("*"); document.writeln("<br>"); } </head> <body> </script> </body> </html>

Write a java script to concatenate two strings separated by space. Name: Shobhit Bhardwaj Roll No.: 7182

<html> <head> <title>concatenate</title> <script type="text/JavaScript"> var n,n1; n=window.prompt("enter the first string"); n1=window.prompt("enter the second string"); n=n.concat(" ",n1); document.writeln("concatenated string is:"+n); </script> </head> <body> </body> </html>

Write a java script to print prime numbers between 2 and 100 Name: Shobhit Bhardwaj Roll No.: 7182 <html> <head> <title>prime nos</title> <script type='text/JavaScript"> document.writeln("prime nos"); var i,j,count; for(i=2;i<=100;i++) { { count=0; for(j=1;j<=i;j++) if(i%j==0) count++; } if(count==2) document.writeln(+i); } </script> </head> <body> </body> </html>

Write a script to input three numbers and display sum, average, product, smallest and largest no in alert box. Name: Shobhit Bhardwaj Roll No.: 7182

<html> <head> <title>q2</title> <script type="text/JavaScript"> var n1,n2,n3,s=0,avg,prod,small,large; n1=window.prompt("enter the first no"); n1=parseInt(n1); n2=window.prompt("enter the second no"); n2=parseInt(n2); n3=window.prompt("enter the third no"); n3=parseInt(n3); s=n1+n2+n3; alert("sum is"+s); avg=(n1+n2+n3)/3; alert("avg is"+avg); prod=n1*n2*n3; alert("prod is"+prod); if(n1>n2&&n1>n3) alert("largest no is"+n1); if(n2>n1&&n2>n3) alert("largest no is"+n2);

else alert("largest no is"+n3); if(n1<n2&&n1<n3) alert("smallest no is"+n1); if(n2<n1&&n2<n3) alert("smallest no is"+n2); else alert("smallest no is"+n3); </script> </head> <body> </body> </html>

Write a script to print product of integers from 1 to 15 Name: Shobhit Bhardwaj Roll No.: 7182

<html> <head> <title>q7</title> <script type="text/JavaScript"> var i; var prod=1; document.writeln("<br>odd integers from 1 to 15 are"); for(i=1;i<=15;i++) { if(i%2!=0) { document.writeln("<br>"+i); prod=prod*i; } } document.writeln("<br>product of these no is:"+prod); </script> </head> <body> </body> </html>

Write a java script to generate random nos Name: Shobhit Bhardwaj Roll No.: 7182

<html> <head> <title>random nos</title> <script type="text/JavaScript"> var n; n=Math.floor(2+Math.random()*(12-2+1)); document.writeln("random no is:"+n); </script> </head> <body> </body> </html>

Vous aimerez peut-être aussi