Understood most everything up to this point now i am stumped


#1

Hello
I have started this course and have loved it so far and haven't had any trouble up until this point.However now I am stuck in lesson 6 on your second "for" loop. I honestly am very confused and not 100% what to even do. Any explanation of whats going on in this would be awesome, and some tips to see where my code is wrong and how to fix it and understand this lesson better would be amazing thanks!

/*jshint multistr:true */
var text =" Hello my name is Clayton, how are you doing today?";
var myName ="Clayton"
var hits = []
for(var i = 0; i < text.length; i++) if (text[i] === "C") for (var j = i; i + myName.length) hits.push(Hello); {
}

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


#2

There are some bracket issues, for starters. Please do not be afraid to use lots of white space. It makes the code much easier to read and debug. See below for the expanded form of your code. The indentation is an indication of nesting.

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

Now examine the code and see if you can spot all the errors/omissions.

Example blocking for the above problem...

for ( ... ) {
    if ( ... ) {
        for ( ... ) {
            # code
        }
    }
}

#3

Thanks for the help ill try to figure it out from here if i need anymore ill post a reply to you thanks!


#4

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