Saturday, August 3, 2019

WT 4 - LEFT MOST VOWEL & REVERSE NUMBER

4. DEVELOP AND DEMONSTRATE A HTML5 FILE THAT INCLUDES JAVASCRIPT SCRIPT THAT USES FUNCTIONS FOR THE FOLLOWING PROBLEMS:

A. PARAMETER: A STRING
B. OUTPUT: THE POSITION IN THE STRING OF THE LEFT-MOST VOWEL
C. PARAMETER: A NUMBER
D. OUTPUT: THE NUMBER WITH ITS DIGITS IN THE REVERSE ORDER

 SOLUTION  1 

prog4.html

<script>
var a = prompt("Enter The Query"),b = parseInt(a),z=0;
if(b) {
while(b>0)
var r= b%10, z= z*10+r, b = Math.floor(b/10);
document.write("Entered Query : "+ a +"<br> Given Number In Reverse Order : "+ z);
}
else {
a = a.search(/[aeiouAEIOU]/);
document.write("The First Occurence Of Vowel is at : "+ (a+1));
}
</script>

OUTPUT - 4A :( click on image to zoom )


OUTPUT - 4B :( click on image to zoom )


 SOLUTION  2 

prog4.html

<!DOCTYPE HTML>
<html>
<body>
<script type="text/javascript">
var str = prompt("Enter the Input","");
if(!(isNaN(str)))
{
var num,rev=0,remainder;
num = parseInt(str);
while(num!=0) {
remainder = num%10;
num = parseInt(num/10);
rev = rev * 10 + remainder;
}
alert("Reverse of "+str+" is "+rev);
}
else
{
str = str.toUpperCase();
for(var i = 0; i < str.length; i++) {
var chr = str.charAt(i);
if(chr == 'A' || chr == 'E' || chr == 'I' || chr == 'O' || chr == 'U')break;
}
if( i < str.length )
alert("The position of the left most vowel is "+(i+1));
else
alert("No vowel found in the entered string");
}
</script>
</body>
</html>

OUTPUT - 4A:( click on image to zoom )



OUTPUT - 4B :( click on image to zoom )



No comments:

Post a Comment