Please what's the problem?!


#1

/*jshint multistr:true */

var text = "Hello there";
var myName = "Esther";
var hits = [];
for(var i = 0; i > text.length; i++)
{
    if(text[i] === "E")
    {
        for(var j = i; j < i + myName.length; j++)
        {
            hits.push(text[j]);
        }
        
    }
}

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

#2

your first for loop:

for(var i = 0; i > text.length; i++)

will never run, look at i > text.length, while i (which starts at zero) is greater then text.length, i would change the condition


#3

You may wish to add your myName variable to the text string.


#4

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