title: Why can't I find the substring in a string?
body: <p>I just want to find whether a sub-string is present in a string, without using any library functions. I know that its very simple and i have done this before in C,C++ and Java. But, I am not getting output in JavaScript. I use the following code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;script type="text/javascript"&gt;
          var j,i;
          var str=window.prompt("Enter the string: ");
          var substr=window.prompt("Enter the string to be searched: ");
          var len=str.length;
          var sublen=substr.length;
          j=0,i=0; 
          whlie(i&lt;len)
          {
              if(str[i]==substr[j])
              {
                  i++;
                  j++;
              }
              else
              {
                  i++;
              }
          }
          if(j==sublen)
          {
              document.write("Substring found");
          }
          else
          {
              document.write("Substring not found");
          }
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>
  Can anyone please tell me, whats wrong with this code.? Thanks in advance..</p>