JS 02 – Best JavaScript program to count the number of vowels in a string

JavaScript program to count the number of vowels in a string

It best and simple Javascript program to count the number of vowels in a give string.

We will be using basic regular expression to solve this program.

Output : Count the number of vowels in a give string using JavaScript

Count Vowels - ITVoyagers
Total number of vowels is -

JavaScript program to count the number of vowels in a give string

HTML code

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Count Vowels - ITVoyagers</title>
</head>
<body>
	<input type="text" name="val" id="inputvalue" value="itvoyagers.in">
	<button id="convert_button" onclick="countVowels()">Count</button>
	<br>
	<div id="outputdiv">
		Total number of vowels is - <span id="outputspan"></span>
	</div>
<!-- itvoyagers.in -->
	<script type="text/javascript" src="countvowels.js"></script>
</body>
</html>

Javascript code (countvowels.js)

var inputvalue = document.getElementById("inputvalue");
var outputspan = document.getElementById("outputspan");
//itvoyagers.in
function countVowels()
{
	outputspan.innerHTML = inputvalue.value.replace(/[^aeiouAEIOU]/g, "").length;
}

Connect with us on following platforms

Leave a Comment