For loops issue


#1


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

when I push j to the array, the console is printing out commas, can't figure out why!

var text = " Drew, fkfdskjh Drew fmksfda. Drew asdsadf";
var myName = "Drew";
var hits = [];

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

console.log(hits);


#2

Check your second for loop.

syntax of for loop

for (first par; second part;third part) {
  //your code
}

Your for loops have semicolons like this (below) which is not acceptable in javascript..

for (first part; second part;third part) ; {
//your code
}

Also you missed the {}, even by default it should work for just one line of code but its safe to use brackets there.


#3

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