· 3 years ago · Dec 07, 2021, 06:40 AM
13. Develop web page using JavaScript to perform the following operations.
2a) create and test a JavaScript to input three integer number using prompt and print the largest among the three-integer number using alert
3<html>
4 <head>
5 <title>TODO supply a title</title>
6 <meta charset="UTF-8">
7 <meta name="viewport" content="width=device-width, initial-scale=1.0">
8 </head>
9 <body>
10 <script> <!-- Javascript file begins-->
11 var a,b,c; <!-- Three numbers for input -->
12 a=prompt("Enter a: "); <!-- Prompt input a -->
13 b=prompt("Enter b: "); <!-- Prompt input b -->
14 c=prompt("Enter c: "); <!-- Prompt input c -->
15 if(a>b) <!-- if loop to compare three numbers -->
16 {
17 if(a>c)
18 alert(a+" is largest"); <!-- largest number is a-->
19 }
20 else if(b>c)
21 alert(b+" is largest"); <!-- largest number is b-->
22 else
23 alert(c+" is largest "); <!-- largest number is c-->
24 </script> <!-- End of javascript file-->
25 </body>
26</html>
27
28OUTPUT:
29
30
31
32
33b)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'.
34<html>
35 <head>
36 <title>upper lower</title>
37 <meta charset="UTF-8">
38 <meta name="viewport" content="width=device-width, initial-scale=1.0">
39 </head>
40 <body>
41 <script>
42 var str='Hello THIS is Web TecHnoLogy LAB'; <!-- Enter input string-->
43 var UPPER='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; <!-- Uppercase alphabets -->
44 var LOWER ='abcdefghijklmnopqrstuvwxyz'; <!-- Lowercase alphabets-->
45 var res=[]; <!-- Result is stored in array-->
46
47 for(var x=0;x<str.length; x++) <!-- looping through characters and swapping the upper to lower and vice-versa -->
48 {
49 if(UPPER.indexOf(str[x])!== -1)
50 {
51 res.push(str[x].toLowerCase()); <!-- to lowercase-->
52 }
53 else if(LOWER.indexOf(str[x])!== -1)
54 {
55 res.push(str[x].toUpperCase()); <!-- to uppercase-->
56 }
57 else
58 res.push(str[x]);
59 }
60 document.write(res.join('')); <!-- Join the result string -->
61 </script>
62 </body>
63</html>
64OUTPUT:
65
66
67
68c) Write a JavaScript to check whether a given value is an valid email or not
69<html>
70 <head>
71 <title>CheckMail</title>
72 <meta charset="UTF-8">
73 <meta name="viewport" content="width=device-width, initial-scale=1.0">
74 </head>
75 <body>
76 <script>
77 e=/^[a-z][0-9 a-z _\.]*@gmail.com/; <!-- Regular expression for email id-->
78 n = prompt("Enter email id:") <!-- Prompt input the email-id-->
79 v=n.search(e); <!--email pattern search-->
80 if(v===-1) <!--if -1 then its not a vaild email id-->
81 alert("Invalid")
82 else <!--else its a vaild email id-->
83 alert("Valid")
84
85 </script>
86 </body>
87</html>