Friday, October 23, 2015

Count the Capital and Small Letters in a Word in JavaScript

This program will ask the user to enter a word or a sentence and then our program will count the capital letters and small letters on it.

If you  have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<html>
<head>
 <script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
 </head>
 <style>
 h3 {
  font-family:arial;
  color:green;
  }
  </style>
<body onload="check_odd_even()">
<script language="javascript" type="text/javascript">
function  check_odd_even() 
   {
    var str = prompt("Enter a word");
var count=0,small=0;
var len=str.length;
  for(var i=0;i<len;i++) {
    if(/[A-Z]/.test(str.charAt(i))) 
{
count++;
    }
else {
 small++;
}
  }
  document.write("<h3>Orignal word : " + str + " <br> No.  of Capital Letters " +count + ". </h3>");
  document.write("<h3>Orignal word : " + str + "<br> No.  of Small Letters "   +small + ". </h3>");
  return count;
}
 </script>
</body >

</html>

No comments:

Post a Comment