Second For loop not working keeping getting error


#1


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


not reading the text and also receiving syntax error


var text = "Im the best DJ in the world.";
var myName = "Coby";
var hits = [];
for (i = 0; i < text.length; i++) {
    if (text[i] === "C") {
        for(var j = i; j < (i + myName.length; j++)
    {
        hits.push(text[j]);
}}}
console.log(hits);


#2

You're missing a parenthesis here: for(var j = i; j < (i + myName.length; j++)


#3

i corrected the parenthesis but now receiving the error " unexpected token"


#4

Nothing in your text string contains "Coby". Your 2nd for loop won't run until "C" appears in the text string.


#5

That's also true, but he's still getting a syntax error.

@djhollywoodcole Could you post the updated code?


#6

[quote="djhollywoodcole, post:1, topic:46367"]
console.log(hits.push);
[/quote]

Just add '.push' to hits


#7

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