5/7 Search Text for Your Name


#1

/*jshint multistr:true */

var text = "bla blah blah blah Gio balh blah blach blach Gio blah blah blah blah";
var myName = "Gio";
var hits = [];
for (i=0; i === text.length; i++){
if (text[i] === "G"){
for (var j = i; j < (myName.length + i); i++) {
hits.push(myName);
hits[0];
}
}
}
console.log(hits);

Don't know what I'm doing wrong. Confused and frustrated.


#2

Instead of "i===text.length", you must do "i < text.length". Also, you must change your "hits".

Example:

hits.push(text[i]);

Also, you do not need that last "hits".

Look into your code, and look at the "hits". Change one into my example above, delete the other "hits", put "i < text.length", and it'll be fixed!

Hope it helped!:smiley:


#3

@ragezapper,
A note to the Editor

  • A word/sentence encapsulated in a pair of double-** will give you
    **Bold** Bold
  • A word/sentence encapsulated in a pair of_underscores_ will give you _Italic_ Italic
  • If you use the \-character, the next-following character is NOT interpreted by the
    Editor, that is how i visualized \_Italic\_
  • The editor will treat a <-character as an opening HTML-Tag

Here I use a h3-tag

fffffff


#4

Oh ok. Got it. :grin: