I need assistance


#1


There is a weird thing that is happening with my code. I've done everything that the exercise has asked for, except it just will not work. What makes this even stranger is that my second for loop is the only thing causing a problem. As a bit of an experiment, I copy/pasted the EXACT CODE from the first exercise in the unit and it STILL WON'T WORK.

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


This is what I keep getting every time I run the code:

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.


/*jshint multistr:true*/
var text = "HEXQEWIUXJACOBWIJSHJENIOQJACOBWLIOQKLN@IH@EKJACOBWEJQ"
var myName = "JACOB"
var hits = []
for(var i = 0; i > text.length; i++) {
    if(text[i] === "J")
    {
        for(var j = i; j < (myName.length + i); j++) {
			hits.push(text[j]);
        }  
    }
}


#2

Is that all your code?
At the bottom, you should have a console.log(arrayname); (Replace arrayname with the name of the array you want to log.
In your text variable you should probably have spaces around your name.
(Like HEXQEWIUXJACOBWIJSHJENIOQJACOBWLIOQKLN@IH@EKJACOBWEJQ could be
HEXQEWIUX JACOB WIJSHJENIOQ JACOB WLIOQKLN@IH@EK JACOB WEJQ)

Hope this helps!!


#3

I guess the problem is in here:

for(var i = 0; i > text.length; i++)

Try changing the operator:

for(var i = 0; i < text.length; i++)

#4

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