Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3. Develop web page using JavaScript to perform the following operations.
- a) create and test a JavaScript to input three integer number using prompt and print the largest among the three-integer number using alert
- <html>
- <head>
- <title>TODO supply a title</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- </head>
- <body>
- <script> <!-- Javascript file begins-->
- var a,b,c; <!-- Three numbers for input -->
- a=prompt("Enter a: "); <!-- Prompt input a -->
- b=prompt("Enter b: "); <!-- Prompt input b -->
- c=prompt("Enter c: "); <!-- Prompt input c -->
- if(a>b) <!-- if loop to compare three numbers -->
- {
- if(a>c)
- alert(a+" is largest"); <!-- largest number is a-->
- }
- else if(b>c)
- alert(b+" is largest"); <!-- largest number is b-->
- else
- alert(c+" is largest "); <!-- largest number is c-->
- </script> <!-- End of javascript file-->
- </body>
- </html>
- OUTPUT:
- b)Write a JavaScript program which accept a string as input and swap the case of each character. For example if you input 'The Quick Brown Fox' the output should be 'tHE qUICK bROWN fOX'.
- <html>
- <head>
- <title>upper lower</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- </head>
- <body>
- <script>
- var str='Hello THIS is Web TecHnoLogy LAB'; <!-- Enter input string-->
- var UPPER='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; <!-- Uppercase alphabets -->
- var LOWER ='abcdefghijklmnopqrstuvwxyz'; <!-- Lowercase alphabets-->
- var res=[]; <!-- Result is stored in array-->
- for(var x=0;x<str.length; x++) <!-- looping through characters and swapping the upper to lower and vice-versa -->
- {
- if(UPPER.indexOf(str[x])!== -1)
- {
- res.push(str[x].toLowerCase()); <!-- to lowercase-->
- }
- else if(LOWER.indexOf(str[x])!== -1)
- {
- res.push(str[x].toUpperCase()); <!-- to uppercase-->
- }
- else
- res.push(str[x]);
- }
- document.write(res.join('')); <!-- Join the result string -->
- </script>
- </body>
- </html>
- OUTPUT:
- c) Write a JavaScript to check whether a given value is an valid email or not
- <html>
- <head>
- <title>CheckMail</title>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- </head>
- <body>
- <script>
- e=/^[a-z][0-9 a-z _\.]*@gmail.com/; <!-- Regular expression for email id-->
- n = prompt("Enter email id:") <!-- Prompt input the email-id-->
- v=n.search(e); <!--email pattern search-->
- if(v===-1) <!--if -1 then its not a vaild email id-->
- alert("Invalid")
- else <!--else its a vaild email id-->
- alert("Valid")
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement