Says my name is not in the text


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-XEDZA/0/7?curriculum_id=506324b3a7dffd00020bf661


The code runs, but it prints that my name wasn't found.


/*jshint multistr:true */

text = "Yo my name is Serendipity and I'm \
pretty cool I guess"; 

var myName = "Serendipity";
var hits = [];

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

if (hits.length === 0) {
	console.log("Your name wasn't found!");
} else {
	console.log(hits);
}


#2

@dipityg,
For the Javascript Interpreter the semi-colon-; is an End-of-Statement indicator.

Thus if you use

for (var i = 0;  i < text.length; i++);

ths means that the following code-block will not be executed.....


#3

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