I've been stuck for like a week. What is the answer so I can see my error


#1



Oops, try again. It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable.


var text = "snuffy";
var myName = "Elmo";
var hits = [ ];

for (i = 0; i < text.length; i++) {
  if ( text[i] === 'E') {
for (var j = i; j < (myName.length + i); j++){
hits.push([j]);    }       
      }  
};
console.log();


#2

j is just a number and it represents a valid index of a character in the target text. That is what you want to push to hits.

What do you want to print in the console here? Put it between the parentheses!

Also, a thought, in your if you are asking if each character in text is equal to "E", but that's never gonna happen because the word is "snuffy" (no "e" there).


#3

var text = "snuffie";
var myName = "Elmo";
var hits = [ ];

for (i = 0; i < text.length; i++) {
if ( text[i] === 'E') {
for (var j = i; j < (myName.length + i); j++){
hits.push([j]); }
}
};
console.log(hits);

Same F in thing


#4

It would be great to get some help!!! I've even tried copying other people code and nothing I'm using moxilla as my browser. What is wrong?


#5

It's not going to find your name if it's not in the text variable. You only wrote snuffie as the value of the text variable so it has nothing to find in regards to var myName. Try writing a couple sentences to the text variable and add "Elmo" in there a few times.


#6

So finally I got my answer.

I changed hits.push([j]); to hits.push(text[j]); and it worked. FyI for all those struggling.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.