-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlab4.html
80 lines (72 loc) · 2.64 KB
/
lab4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!doctype html>
<html>
<head>
<style>
.container{
width:350px;
height:220px;
border:1px solid blue;
margin-left:37%;
}
.element{
margin-left: 25%;
margin-top: 8%;
}
span{
color: green;
margin-left: 20%;
}
</style>
</head>
<body>
<h1 style="text-align:center;">Vowel and Reverse of a number</h1>
<div class="container">
<input type="text" placeholder="Enter a String" id="string"
class="element" /><br>
<input type="text" placeholder="Enter a Number" id="number"
class="element" /><br>
<button type="button" id="submit" onclick="getData()"
style="margin-left: 40%;margin-top:
8%;color:blue;"> Submit </button><br><br>
<span id="stringResult"></span><br>
<span id="numberResult"></span>
</div><br>
<footer>
<b style="margin-left: 42%;">Made with <i style="color:red;">♥</i>
by Sujith D</b>
</footer>
<script>
function getData(){
var string = document.getElementById('string').value;
var number = document.getElementById('number').value;
if(string == "" || number == "" ){
alert("Enter all the fields");
return;
}
if(isNaN(number)){
alert("Enter a valid number");
return;
}
var vowel = processString(string);
document.getElementById('stringResult').innerHTML = vowel;
var reversedNumber = processNumber(number);
document.getElementById('numberResult').innerHTML = reversedNumber;
}
function processString(string){
string = string.toUpperCase();
for(var i = 0; i < string.length; i++){
ch = string.charAt(i);
if(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
break;
}
if( i < string.length )
return "Left most vowel " + ch +" found at position " +(i+1)
else
return "No Vowel Found"
}
function processNumber(number){
return "Reversed Number = " + String(number).split("").reverse().join("");
}
</script>
</body>
</html>