SyntaxError: Unexpected token for Your second "for" loop


#1


Again stuck on Syntax and for the life can't figure it out. Please help!!


/*jshint multistr:true */

var text = "This is my text string";
var myName = "Dennis";
var hits = [];

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


#2

HI this line

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

put it like that

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

#4

I've tired moving the parenthesis but doesn't fix it :frowning:


#5

In this variable (in the string)

var text = "This is my text string";

you should at least put once your name


#6

Still saying SyntaxError: Unexpected token


#7

CAn you post your new code?


#8

/*jshint multistr:true */

var text = "Hello, my name is Dennis and this ■■■■ is going down hill fast.";
var myName = "Dennis";
var hits = [];

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


#9

HI this line

if (text[i] === MyName[0])

you wrote MyName instead of myName

Then

here

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

you should put the closing ) before the ;

;

so it should be like that


#10

SMH wow... That worked! Thanks a lot for your help!


#11

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