Second for loop


Hi good coders.
the second for loop isn't functioning. I read all the answers and tried them, nothing seem to be helping. any Ideas?
thanks in advance

var text ="my name is mahmoud shahin";
var myName="Shahin";
var hits = [];
for(var i=0;i< text.length ; i=i+1){
if(text[i] === myName[0] ){
for(var j = i; j < (myName.length + i); j++){
any Idea what's happening here


@mahmoudshahin, before second loop you check does var text contain the 1st symbol of var myName. It means that you try to find in var text symbol 'S'. So, condition if(text[i] === myName[0] ) always returns false, because var text doesn't contain symbol 'S'. Try:

var text ="my name is Mahmoud Shahin";


This is working code! var text have to start with the first letter of your name. Check it out in example bellow.

var text = "Nemanja se ubi sa ovim kodom.";
var myName = "Nemanja";
var hits = [];

for(var i=0; i<text.length; i++) {
if (text[i] === 'N') {
for (var j=i; j<(i+myName.length); j++) {


Name can be anywhere in the var text. Why do you think so???
His problem was that he trying to find symbol 'S' which is not in var text.


Yes, the name can be anywhere in the var text


hahahah what a clumsy mistake :smiley: thanks mate


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