How To Count Capital And Small Letters Using JavaScript
Submitted by alpha_luna on Saturday, April 30, 2016 - 14:58.
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
This is the output:
Ask the user to enter a word or a sentence.
This is the 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.
- <script language="javascript" type="text/javascript">
- function check_odd_even()
- {
- var str = prompt("Enter your word to count the Capital and Small Letters.");
- 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 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>");
- 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>");
- return count;
- }
- </script>
Add new comment
- 83 views