5. Incorrect print



I'm not sure what's wrong. I tried a couple of the fixes I found in other answers with no luck. I don't get any errors but the output is all wrong and I can't figure out how to fix it. it is printing way too many characters I think to the array, and then at the bottom it just says undefined a bunch. Bugging me...

 /*jshint multistr:true */
var text = "I, Colten, lord of the Sea Monkeys, have returned to save you all from the dreaded Spaghetti monster"

var myName = "Colten";

var hits = [];

for (var i = 0; i < text.length; i ++) {
    if (text[i] === 'c'); {
        for (var j = i; j < (myName.length + i); j ++); {
 if (hits.length === 0) {
     console.log("Your name wasn't found!");
 } else {


OK, so I swapped the j and i in this line:

for (var j = i; j < (myName.length + i); j ++); {

so it now reads

for (var i = j; j < (myName.length + i); j ++); {

and all I get is [ undefined ]


As answer to your Original Post
For Javascript the semi-colon-; is an End-of-Statement indicator....

If the Javascript interpreter encounters

if (text[i] === 'c');

it will not see the following code-block

        for (var j = i; j < (myName.length + i); j ++); {

as being part of the IF statement.....
for every text[i]
the code 2nd FOR-loop code-block will be executed.....

As your name starts with a capital-C
you will have to change the IF condition

(text[i] === 'C')


Awesome!! Now I understand a bit better the use of the semi-colon. Thank you very much for you input.


Here some