5/7 I tried everything, please help


#1

var text = ("marko", "david", "saso", "daniela")
myName = ("Teodor");
var hits = []
for (i = 0; i < text.length; i++)
{
if (text[i] === 'T')
{
for (var j = i; j < i + myName.length; j++);
hits.push(text[j])
}
}

console.log(hits)


#2

The problem is in your text variable. You're trying to create and array without using the brackets []. You shouldn't use an array here anyways so replace

var text = ("marko", "david", "saso", "daniela")

With something like

var text = "Lorem ipsum dolor sit amet, Teodor consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Teodor ut enim ad minim veniam, quis nostrud exercitation Teodor ullamco laboris nisi ut aliquip ex ea commodo consequat."

You don't have to print anything just yet in this step. The code below should function properly.

var text = "Lorem ipsum dolor sit amet, Teodor consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Teodor ut enim ad minim veniam, quis nostrud exercitation Teodor ullamco laboris nisi ut aliquip ex ea commodo consequat.";
var myName = "Teodor";
var hits = [];

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

#3

But for you to see the result of your construct
you should add 1 more code-line

console.log( hits );

#4

That's true, but he'll get to that in the next step anyways so it's not necessary.