Exp-9 Create event-driven JavaScript program for the following. Make use of appropriate variables, JavaScript inbuilt string functions and control structures

write this on the writing side

To accept string from user and count number of vowels in the given string.

<!DOCTYPE html>
<html>
<head>
	<title>Sop 3 JAVasript Count vowels</title>
</head>
<body>
<form name="form1">
	<h1>Enter the String whose vowel isto be counted</h1>
	<input type="text" name="text1"> 
	<input type="button" name="btn_checkvowel" value="Click to count" onclick="count()">
</form>
<script type="text/javascript">
	function count()
	{
		var i,ch,str,counter=0;
		str=form1.text1.value;
		for(i=0;i<str.length;i++)
		{
			ch=str.charAt(i);
			if(ch=='A'||ch=='a'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
				counter++;
		}
		alert("Number of Vowels in Entered String is:"+counter);
	}
</script>
</body>
</html>

stick this output on the blank side

Leave a Comment

Scroll to Top