How To Count Capital And Small Letters Using JavaScript

In this program, we are going to learn on How To Count Capital And Small Letters Using JavaScript. This program, ask the user to type the desired sentence or a word then, by clicking the “OK” button it will automatically count the Capital and Small Letters. JavaScript
  1. <script language="javascript" type="text/javascript">
  2. function check_odd_even()
  3. {
  4. var str = prompt("Enter your word to count the Capital and Small Letters.");
  5. var count=0,small=0;
  6. var len=str.length;
  7. for(var i=0;i<len;i++) {
  8. if(/[A-Z]/.test(str.charAt(i)))
  9. {
  10. count++;
  11. }
  12. else {
  13. small++;
  14. }
  15. }
  16. document.write("<h3 style='text-align:center;'><b style='color:blue;'>Orignal word :</b> <b style='color:red;'>" + str + "</b> <br> No. of Capital Letters is <b style='color:blue;'>" +count + "</b>. </h3>");
  17. document.write("<h3 style='text-align:center;'><b style='color:blue;'>Orignal word :</b> <b style='color:red;'>" + str + "</b> <br> No. of Small Letters is <b style='color:blue;'>" +small + "</b>. </h3>");
  18. return count;
  19. }
  20. </script>
This is the output: Ask the user to enter a word or a sentence. Ask the UserThis is the result: Result This is a simple program and suited for the beginner. Kindly click the "Download Code" below for full source code. So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment