5/7 Search Text For Your Name


#1

Hello

I've hit a wall with 5.7 adding the second for loop.. I think I have read and compared my code to every thread for this question, but I'm still none the wiser to why the second 'for' loop is not pushing values :frowning: . I really want to understand this by moving on. Can someone please assist me on this question...

*MY CODE>>>>>

var text = "bla blalknnl nlknlknklnlkn Charlotte gregerg.";
var myName = "Charlotte";
var hits = [];

for (i=10; i<text.length; i++);{
if(text[i] === myName[0]) {


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


#2

if(text[i] === myName[0]) { should be if(text[i] === "C") { (Since myName starts with "C"


#3

The jshint line should be at the very top of the code.

Multiple errors in the above line:

  • it should start at 0, not 10.
  • the token between the paren and the brace is invalid and actually terminates the loop before it even starts.
  • generally, the code does not have enough braces... There should be three pairs. for, if, for.

#4

thank you, I think I changed this to 0 when looking at other threads.


#5

Many thanks Roy, appreciate you taking the time to look at my code. I think I have been staring at it too long not being able to see the errors :-/ combined with comparing it to other threads regarding this question.


#6

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