Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>if else</title>
- </head>
- <body>
- <script>
- var x=1, y=3, ans=0;
- if(x>y)
- ans=x-y;
- else
- ans=y-x;
- document.write("ans=", ans);
- </script>
- </body>
- </html>
- -----------------------------------------------------------------------------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <title>Greatest No</title>
- </head>
- <body>
- <script>
- var v1=parseInt(prompt("Value 1:"));
- var v2=parseInt(prompt("Value 2:"));
- var v3=parseInt(prompt("Value 3:"));
- if(v1>v2)&&(v1>v3)
- document.write("Greatest no is : ", v1);
- elseif(v2>v3)
- document.write("Greatest no is : ", v2);
- else
- document.write("Greatest no is : ", v3);
- </script>
- </body>
- </html>
- -----------------------------------------------------------------------------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <title>Switch</title>
- </head>
- <body>
- <script>
- var n=parseInt(prompt("Enter a no:"));
- switch(n)
- {
- case 1:
- document.write("January");
- break;
- case 2:
- document.write("February");
- break;
- case 3:
- document.write("March");
- break;
- case 4:
- document.write("April");
- break;
- case 5:
- document.write("May");
- break;
- case 6:
- document.write("June");
- break;
- case 7:
- document.write("July");
- break;
- case 8:
- document.write("August");
- break;
- case 9:
- document.write("September");
- break;
- case 10:
- document.write("October");
- break;
- case 11:
- document.write("November");
- break;
- case 12:
- document.write("December");
- default:
- document.write("Invalid No");
- }
- </script>
- </body>
- </html>
- -----------------------------------------------------------------------------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <title>while</title>
- </head>
- <body>
- <script>
- var a=0;
- while(a<=10)
- {
- document.write("<br>", a++);
- }
- </script>
- </body>
- </html>
- -----------------------------------------------------------------------------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <title>do while</title>
- </head>
- <body>
- <script>
- var x=50;
- do
- {
- document.write("<br>", x);
- x++;
- }while(x<=10);
- </script>
- </body>
- </html>
- -----------------------------------------------------------------------------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <title>for</title>
- </head>
- <body>
- <script>
- var x;
- for(x=1;x<=6;x++)
- document.write("<h"+x+">Heading "+x+"</h"+x+"><br>");
- </script>
- </body>
- </html>
- -----------------------------------------------------------------------------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <title>forin</title>
- </head>
- <body>
- <script>
- var sub={s1:'OOPs',s2:'MA',s3:'WP',s4:'NSM',s5:'GC'};
- for(var s in sub)
- document.write(s+":"+sub[s]+"<br>");
- </script>
- </body>
- </html>
- -----------------------------------------------------------------------------------------------------------------
- <!DOCTYPE html>
- <html>
- <head>
- <title>break</title>
- </head>
- <body>
- <script>
- var x;
- for(x=1;x<=10;x++)
- {
- if(x==3)
- break;
- document.write("<br>", x);
- }
- </script>
- </body>
- </html>
- -----------------------------------------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment