-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram4
73 lines (73 loc) · 2.15 KB
/
Program4
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
<!DOCTYPE html>
<html>
<head>
<title>Left Most Vowel & Reversal of a Number</title>
<style >
body{
background-color: #FFFDD0;
color:#8C8833;
margin: 30px;
}
#resultS, #resultN{
display: block;
background-color: #FFFFFF;
}
#warningN{
color:red;
font-style:italic;
}
</style>
</head>
<body>
<header><h1>Javascript functions</h1></header>
<nav>
<ul>
<li>Find Left Most Vowel</li>
<li>Reverese of Number</li>
</ul>
</nav>
<section>
<h2 id="option">Choose an option</h2>
<article>
<h3> Find the left most vowel </h3>
<p>
Enter a string: <input id ='paramS' type='text' size='10' /><br />
<button onClick='lvowel()'> Enter </button>
</p>
<p id="resultS"> </p>
</article>
<article>
<h3> Find the reverse of a number </h3>
<p>
Enter a number: <input id ='paramN' type='text' size='10' /> <span id="warningN"></span> <br /> <button onClick='rev()'> Enter </button>
</p>
<p id="resultN"> </p>
</article>
</section>
</body>
<script>
function lvowel(){
var str = document.getElementById("paramS").value.toUpperCase();
for(var i=0; i<str.length; i++){
chr = str.charAt(i);
if(chr=='A' || chr=='E' || chr=='I' || chr == 'O' || chr=='U'){
document.getElementById("resultS").innerHTML="The leftmost vowel is in position "+(i+1);
break;
}
}
}
function rev(){
var num = document.getElementById("paramN").value;
if(isNaN(num)){
document.getElementById("warningN").innerHTML = "Enter a valid Number!"; return;
}
else
document.getElementById("warningN").innerHTML = "";
var rev="";
for(var i=num.length-1; i>=0;i--){
rev+= num.charAt(i);
}
document.getElementById("resultN").innerHTML="The reverse is "+rev;
}
</script>
</html>