title: while loop keep timing out, can't figure out why(Hackerrank problem)
body: <p>I'm doing the repeatedString problem on Hackerrank and my code won't past all the cases. My code seem right, but it would timeout when taking a large integer </p>
  
  <p>I tried using different for loops but i can't seem to figure it out, I'm somewhat new to coding. I tried doing an if statement saying if s equal 'a' then count equal n, but that don't help it pass all test cases. I'm pretty sure you can google the repeatedStr problem if you need to see it.</p>
  
  <p>From the code i put i expect count to equal n.</p>
  
  <pre><code>function repeatedString(s, n) {
      let count = 0
      let subStr = ''
  
      while (subStr.length &lt;= n) { //it times out
          for (let i = 0; i &lt; s.length; i++){
              let element = s[i]
              if (element) {
                  subStr += element
              }
          }
      }
      for (let j = 0; j &lt; subStr.length - 1; j++){
          let element = subStr[j]
          if (element === 'a') {
              count++
          }
      }
      return count
  }
  
  repeatedString('a', 100000000)
  </code></pre>