A simple program that I wrote that will ask the user to give a string or sentence and then the program will count the number of words in the given string or sentence using JavaScript programming.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City I also accepting computer repair, networking, and Arduino Project development at a very affordable price. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com

If you like this video please click the LIKE button, SHARE, and SUBSCRIBE to my channel.

Your support on my channel is highly appreciated.

Program Listing

<html>
  <title>Word Count in JavaScript </title>
 <body>
 	<style type="text/css">
 	
 	body {
       font-family: arial;
       font-weight: bold;
       font-size: 15px;

 	}

 	</style>
 	<script type="text/javascript">
function countWords(){
	s = document.getElementById("inputString").value;
	s = s.replace(/(^\s*)|(\s*$)/gi,"");
	s = s.replace(/[ ]{2,}/gi," ");
	s = s.replace(/\n /,"\n");
	document.getElementById("wordcount").value = s.split(' ').length;
}

function clear_text_area() {
	document.getElementById("wordcount").value = "";
	document.getElementById("inputString").value = "";
	document.getElementById("inputString").focus();
}
</script>
<h1>Count Words Using JavaScript </h1>
<h4> Jake Rodriguez Pomperada, MAED-IT, MIT</h4>
<form name="form1" method="post" action="">
  <textarea name="inputString" id="inputString" cols="50" rows="4"></textarea>
<br /><br><br>

Number of Words  &nbsp;&nbsp;<input name="wordcount" id="wordcount" type="text" value="" size="6"><br><br>
<input type="button" name="Convert" value="Count Words" onClick="countWords();"> &nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="Clear" value="Clear" onClick="clear_text_area();"> 
</form>
</body>
</html>

Leave a Reply

Your email address will not be published.