4. Search text for your name


I need help figuring this out, it says syntax error.

for (var i=0; i >= text.length; i++) { if ( var myName = "stephen";


updated code :

var myName = "stephen"
var hits = [ ]

for (var i = 0; i < text.length; i++);
if ( myName[0] ==="s")


figured it out. thanks


for (var i = 0; i < text.length; i++);
if ( text[i] ==="s")


To be able to demonstrate more fully what the goal of this exercise is, it helps if we have a large block of text.

/*jshint multistr:true */
text = "In diam diam, molestie Stephen nec ullamcorper id, condimentum \
id mauris. Sed lacinia libero Stephen vitae massa hendrerit vitae porttitor \
mauris porta. Praesent Stephen dapibus vestibulum semper. Aenean posuere \
suscipit accumsan. Phasellus ac arcu Stephen arcu. Phasellus sodales \
venenatis mollis. Fusce dignissim Stephen mollis tortor sed fermentum. \
Pellentesque egestas, Stephen mi in accumsan tempor, justo felis.";
myName = "Stephen";
hits = [];

Remember, the objective is to match only the first letter of your name, then iterate through that segment of the text, pushing the first letter and six more (doesn't matter what they are) to the hits array. This will also get pushed to the array: 'S', 'e', 'd', ' ', 'l', 'a', 'c'

    if (text[i] === myName[0]) {
        // inner loop code


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