Mastering Development

lettter count is not repting in givinen input on javascript using -> document.elemetbyid

check the error i give the input as a string and i want to output as a letter count . how many >> time letter is present in string

   <!DOCTYPE html>
       <script type="text/javascript">
         function my() {
                       var st = document.getElementById("j").value;
                           var s = "l" ;

                        var letter_Count = 0;
    for (var position = 0; position < st.length; position++) 
       if (st.charAt(position) == s) 
         letter_Count += 1;
     document.getElementById("demo").innerHTML = letter_Count;
       <p id="demo"></p>
       <input type="text" name="j" id="j" onkeyup="my()" />

Leave a Reply

Your email address will not be published. Required fields are marked *