Your Second "for'' Loop


#1

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

An error that says: 'Oops, try again. There was a problem with your syntax.' keeps popping up. This shows on the black screen: 'SyntaxError: Unexpected end of input'


Replace this line with your code. 
/*jshint multistr:true */
var text = "Mesonma, Mesonma, Mesonma, whatever, fun";
var myName = "Mesonma";
var hits = [];
for (i=0; i<text.length; i++){
    if (text[i] === 'M'){
        for(var j = i; j<i+myName.length; i++){
            hits.push(text[i]);
        };
};


#2

HI this line

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

you should increase j++ instaed of i++


#3

This is the error to focus upon since it is the compiler raising it. The error generally indicates a missing curly brace so let's look for that.

There are three { and only two }. The if statement is not closed.

Aside:

We never write semi-colons after } unless it closes an object literal or a function expression.

var myObject = {

};

var myFunc = function () {

};

#4

I changed it now, but it's still giving me the same error.


#5

Now read the post made by @mtf


#6

Ok, yes this helped. Thank you both.


#7

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