What's wrong with my second for loop? I've been starring at it for hours


I've been trying to work out this second for loop thing for ages and I have no idea why it won't work, I swear the syntax is perfect.

/*jshint multistr:true */
var text = "This is a string of random Chris text which will randomly Chris include my name within it";
var myName = "Chris";
var hits = [];
for (var i = 0; i < text.length; i++) {
    if (text[i] === "C") {
        for (var j = i; j < myName.length + i; j++) {


It seems like your approach here would grab any word that started with a capital 'C'. Once you identify the start and grab the appropriate number of letters, you should probably check what you have before you commit it to 'hits'.



can you post the link of your exercise and what error it throws?

we can help you better this way.

Your code is fine but it may not be what the lesson wanted.


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