Totally stuck! probably a stupid error that i can't find


'Oops, try again. It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable.'

I tried some stuff, and looked on the forum, and even put in some console.log segments to try and see what part of the code was going wrong, but nothing seemed to help.

/*jshint multistr:true */

var myName = 'Johnny'
var text = 'The worst thing that could happen in the world is if Johnny got hit by a car. Johnny is also the most annoying person that i have ever seen! could you tell melissa that I do not want any Girlscout cookies. Johnny hates them';
var hits = [];

for (var i = 0; i > text.length; i++) {
    if (text[i] === "J")
        for (j = i; j >= i + myName.length; j++) {


the exercise url is the same for everyone, please copy paste your code to the forum so we can help you


Sorry, i accidentally submitted the post while i was in the middle of creating it.


conditions of both your loop evaluate to false immediately, so neither loops run


The code of the first for loop, and first if loop were created in previous lessons, so i am not sure why it is not running. Also, could you specify why it is evaluating to false?


for the first iteration of the loop, we would have the following condition:

0 > 223

which is false, the loop will run for as long as the condition is true


I was under the impression that that was the end point, and the for loop would run until that was true.
for (start-point; endpoint; increment) {


yes, the loop runs as the end point condition is true

your end point condition is false the first time its evaluated


I believe you misunderstood what i said, sorry for the confusion. I thought that the code would run while the second segment was false, and end when the second segment became true. Thank you for clearing that up.


no, its the other way around. The loop runs while condition evaluate to true

now you figured this out, you should be able to solve the problem?


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