4. Search text for your name


#1


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



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


#2

updated code :

var myName = "stephen"
var hits = [ ]

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


#3

figured it out. thanks


#4

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


#5

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
    }

#6

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