Question: I am trying to understand this JS function:
[JS Fiddle Demo](http://jsfiddle.net/hx5NY/)

I basically got it out of a book that I am trying to learn from. The book is called "JavaScript: The Definitive Guide" (pg484). But the function does not include the html that goes with it. I'd appreciate if someone could help me write the html that would make this work, thereby I might be able to get a better understanding how it works. I have made a stab at this with the link above. 

I really don't like this book the way it does this. It happens a lot. I am a novice, does anyone have advice of what to do other than just come on here and try and get an answer.

Appreciate any help.

```
//Example 17-7. Using the propertychange event to detect text input
function forceToUpperCase(element) {
  if (typeof element === "string") element = document.getElementById(element);
  element.oninput = upcase;
  element.onpropertychange = upcaseOnPropertyChange;
  // Easy case: the handler for the input event
  function upcase(event) { this.value = this.value.toUpperCase(); }
  // Hard case: the handler for the propertychange event
  function upcaseOnPropertyChange(event) {
    var e = event || window.event;
    // If the value property changed
    if (e.propertyName === "value") {
      // Remove onpropertychange handler to avoid recursion
      this.onpropertychange = null;
      // Change the value to all uppercase
      this.value = this.value.toUpperCase();
      // And restore the original propertychange handler
      this.onpropertychange = upcaseOnPropertyChange;
    }
  }
}

```

Answer: 
Your code looks good, but you're not getting output because you're not printing it!

Simply add a `System.out.println(...)` to your main method.

```
System.out.println("Frequency is: " + c.freq(input, p));

```
For this part:

> 
> I looked online and found the freq(c.substring(1, c.length()),p); part but going through the code it doesn't make sense.. seems like on every pass its still going to deal with 'aa' and not necessarily shrink it.
> 
> 
> 

The line `c.substring(1, c.length())` shrinks the String `c` so that what gets passed into the recursive call has one less character to process and thus, helping the recursive call to eventually reach the termination condition of `c.length() == 0`. So, it is safe to assume that `freq` method's implementation is correct.