7/7 - Passed but won't print my name?


Hey guys,
I've looked through the entire thread & can't find anything similar. My code "passed" all the way to the end, but instead of printing my name it either prints: [ 'C', 'C' ] when entering hits.push(text[i]); or [ '.', ' ' ] when entering hits.push(text[j]);
Here's my syntax:
/*jshint multistr:true */
var text = "My name is Cindy. The name Cindy means \
var myName = "Cindy";
var hits = [];
for (var i = 0; i < text.length; i++){
if(text[i] === myName[0]) {
for(var j = i; j < (myName.length +i); j++); {
if(hits.length === 0) {
console.log("Your name wasn't found!");
} else {

Thanks for your help/feedback!


Your inner for loop has a semi-colon after the conditional statements: " for (var j = i; j < (myName + i ); j++); { "

Remove that semi-colon and it will execute as expected.

The way you have it written is effectively this:

for (var j = i; j < (myName + i ); j++) {
//do nothing

Which is why you are seeing the "," and " " being output.


Somehow I knew it would be an extra semi-colon somewhere! Thanks so much!!! :smile:


I had the same issue with the superfluous semicolon. Thanks for helping with this! Could you explain why


would output the punctuation like it did?

Does the semicolon cause the counter to jump to its final working value (j === i + myName.length) so that that value is stored in the variable j when it is referenced?