Log it! it works, but


so my code works according to code academy, but it prints out the entire "text" string instead of just hits, is this normal? when i run it, it ends up printing out each letter of the entire "text" string 7 times, then it moves on to the next letter. when all the letters have been printed, it prints out "undefined" 7 times. is this normal?here's my code:

var text = "Oooh, who lives in a pineapple under the sea?! twondai!";
var myName = "twondai";
var hits = [];

for (i = 0; i <= text.length; i++) {
if (text[i] = "t"){
for (j = i; j < (i+myName.length); j++){
if(hits.length === 0){
console.log("Your name wasn't found!")


I think the problem is on the second loop, when you’re trying to log the text.
for example, the length of the text is 30, and the length of myName is 7
when i=29, j is ranged from 29 to 36.
the problem is, your text length only 30, so there’s no text[30], text[31],……text[36]

i guess the solution is either:
1. change the first loop to "for (i = 0; i < text.length-myName,length; i++)”
2. or add some condition inside first loop to check if i+myName.length < text.length
if (i+myName.length < text.length)
///add second loop here