sauLVP

pracs

Jan 17th, 2018
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.35 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>if else</title>
  5. </head>
  6. <body>
  7. <script>
  8.     var x=1, y=3, ans=0;
  9.     if(x>y)
  10.          ans=x-y;
  11.     else
  12.         ans=y-x;
  13.     document.write("ans=", ans);
  14. </script>
  15. </body>
  16. </html>
  17.  
  18. -----------------------------------------------------------------------------------------------------------------
  19.  
  20. <!DOCTYPE html>
  21. <html>
  22. <head>
  23. <title>Greatest No</title>
  24. </head>
  25. <body>
  26. <script>
  27.     var v1=parseInt(prompt("Value 1:"));
  28.     var v2=parseInt(prompt("Value 2:"));   
  29.     var v3=parseInt(prompt("Value 3:"));
  30.     if(v1>v2)&&(v1>v3)
  31.          document.write("Greatest no is : ", v1);
  32.     elseif(v2>v3)
  33.          document.write("Greatest no is : ", v2);
  34.     else
  35.          document.write("Greatest no is : ", v3);
  36. </script>
  37. </body>
  38. </html>
  39.  
  40. -----------------------------------------------------------------------------------------------------------------
  41.  
  42. <!DOCTYPE html>
  43. <html>
  44. <head>
  45. <title>Switch</title>
  46. </head>
  47. <body>
  48. <script>
  49.     var n=parseInt(prompt("Enter a no:"));
  50.     switch(n)
  51.     {
  52.         case 1:
  53.             document.write("January"); 
  54.             break; 
  55.         case 2:
  56.             document.write("February");
  57.             break; 
  58.         case 3:
  59.             document.write("March");   
  60.             break;
  61.         case 4:
  62.             document.write("April");   
  63.             break;
  64.         case 5:
  65.             document.write("May"); 
  66.             break;
  67.         case 6:
  68.             document.write("June");
  69.             break;
  70.         case 7:
  71.             document.write("July");
  72.             break;
  73.         case 8:
  74.             document.write("August");  
  75.             break;
  76.         case 9:
  77.             document.write("September");   
  78.             break;
  79.         case 10:
  80.             document.write("October"); 
  81.             break;
  82.         case 11:
  83.             document.write("November");
  84.             break;
  85.         case 12:
  86.             document.write("December");
  87.         default:
  88.             document.write("Invalid No");          
  89.     }
  90. </script>
  91. </body>
  92. </html>
  93.  
  94. -----------------------------------------------------------------------------------------------------------------
  95.  
  96. <!DOCTYPE html>
  97. <html>
  98. <head>
  99. <title>while</title>
  100. </head>
  101. <body>
  102. <script>
  103.     var a=0;
  104.     while(a<=10)
  105.     {
  106.         document.write("<br>", a++);
  107.     }
  108. </script>
  109. </body>
  110. </html>
  111.  
  112. -----------------------------------------------------------------------------------------------------------------
  113.  
  114. <!DOCTYPE html>
  115. <html>
  116. <head>
  117. <title>do while</title>
  118. </head>
  119. <body>
  120. <script>
  121.     var x=50;
  122.     do
  123.     {
  124.         document.write("<br>", x);
  125.         x++;
  126.     }while(x<=10);
  127. </script>
  128. </body>
  129. </html>
  130.  
  131. -----------------------------------------------------------------------------------------------------------------
  132.  
  133. <!DOCTYPE html>
  134. <html>
  135. <head>
  136. <title>for</title>
  137. </head>
  138. <body>
  139. <script>
  140.     var x;
  141.     for(x=1;x<=6;x++)
  142.         document.write("<h"+x+">Heading "+x+"</h"+x+"><br>");
  143. </script>
  144. </body>
  145. </html>
  146.  
  147. -----------------------------------------------------------------------------------------------------------------
  148.  
  149. <!DOCTYPE html>
  150. <html>
  151. <head>
  152. <title>forin</title>
  153. </head>
  154. <body>
  155. <script>
  156.     var sub={s1:'OOPs',s2:'MA',s3:'WP',s4:'NSM',s5:'GC'};
  157.         for(var s in sub)
  158.             document.write(s+":"+sub[s]+"<br>");
  159. </script>
  160. </body>
  161. </html>
  162.  
  163. -----------------------------------------------------------------------------------------------------------------
  164.  
  165. <!DOCTYPE html>
  166. <html>
  167. <head>
  168. <title>break</title>
  169. </head>
  170. <body>
  171. <script>
  172.     var x;
  173.     for(x=1;x<=10;x++)
  174.     {
  175.         if(x==3)
  176.         break;
  177.         document.write("<br>", x);
  178.     }
  179. </script>
  180. </body>
  181. </html>
  182.  
  183. -----------------------------------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment