5/7 can you check please


#1

var text="bla bla,i am Stefano,bla bla bla Stefano,bla bla Stefano";
var myName="Stefano";
var hits=[]
for (var i=0; i if(text[i]===myName"S"){
for (var j=i; j<(i+myName.length); j++){
hits.push(text[j]);

}

}
}
Hi Guys.
i was looking also the previous post about it, but i'm not able to find the error (Oops, try again. There was a problem with your syntax.) Can you have a check??thanks


#2

@chipninja28228,

You should have a look at your FOR-loop

for (var i=0; i if(text[i]===myName"S"){

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for


#3

....i don't understand....because before instead of "S" i was using [0] but it didn't work and i looked the forum and i changed to "S" and also 'S'.....but didn't work....


#4

@chipninja28228,

Try using

var text="bla bla,i am Stefano,bla bla bla Stefano,bla bla Stefano";
var myName="Stefano";
var hits=[]
for (var i=0; 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 );

#5

thanks:grinning:....your code works...but i don't understand what was wrong.....:scream:


#6

@chipninja28228,

....


#7

yes....but at my first attempt i wrote [0] but i had error and then i started to see the forum here and all persons write the first letter of the name....and i changed it((((