Your second "for" loop


Just trying to figure out why the output on my code is 85 and not 15. Should the output be 85?

var text = "Scott Scott Scott";
var myName = "Scott";
var hits = [];/*jshint multistr:true */
for(var i = 0; i < text.length; i++){
    if(text[0] === "S"){
        for(var j = i; j < myName.length + i; j++){


Line 5 if (text[0] === "S") { //change [0] to [i] //your code should look like Line 5 if (text[i] === "S") {

Line 6 for (var j = i; j < myName.length + i; j++){ /// add brackets // your code should look like this for(var j = i; j < (myName.length + i); j++){


Thanks for your help.

I had already saved and submitted the code. When I reset the code and added the changes it did not output
the result. It just moved me on to the next code lesson. I even tried going back to the very beginning of the "for" loop lesson so I could get to that particular coding exercise but it skipped right over it. I'm guessing it's because I had already submitted the code. Even though the code was not correct. That's about the 3rd time I saved and submitted a code and it was considered correct when clearly it wasn't correct and it wasn't completed.

So now my understanding is certain parts of the code in some of the assignments don't have to be 100% completed or correct in order to move on to the next coding lesson; they just want learners to understand what's going on in the code.
I was just thinking out loud.:slight_smile:

Once again I really do appreciate you taking the time to look my code over.


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