Exact name not found


#1

var text="Hello,How are you Archit?";
var myName="How";
var hits=[];

for(var i=0; i{
if(text[i]==='H')
{for(var j=i;j {hits.push(text[j]);
}

}
if(hits.length===0)
console.log("Your name wasn't found!");
else


console.log(hits);

}

This is my code. But even if I wish to find just How, it even prints "Hel" of hello too. How can this be solved?


#2

Your two for loops are not written correctly. Do you know the basic structure of a for loop?


#3

Hello @archits06,

you should go back a few chapters and learn how to properly set up if-statements and/or loops:confused:


#4
var text="Hello,How are you Surendra?";

var myName="How";
var hits=[];

for(var i=0; i{
if(text[i]==='H')
{for(var j=i;j {hits.push(text[j]);
}

}
if(hits.length===0)
console.log("Your name wasn't found!");
else


console.log(hits);

}

\This is my code. Sorry last time could not copy paste properly. The output shows Hel and How both


#5

and yes, include these conditions after for(var i=0;i I dont know why it is not being pasted in my original reply. thats my whole for loop for the var i.


#6

@archits06, you still should check again, how to make if-statements and for-loops properly.

Otherwise your code will never work, and if you don't understand such "basics", you shouldn't proceed to the next exercises.