I need help on "Your second 'for' loop"


#1

There appears to be a syntax error, a "Unexpected identifier", in my code. Here it is:

/*jshint multistr:true */
var text = "Hello, my name is Jordan."
var myName = "Jordan"
var hits = [];
for (var i = 0; i < text.length; i++) {
if(text[i]==='J') {
console.log(myName);
for(var j = i;
newArray = [];
newArray.push('hello')
newArray[0]; // equals 'hello'
}

}

I would appreciate any help to assist me in figuring out the issue. Thanks!


#2

Hi @jp_lakers_coder,

console.log(myName); is not needed here.

The chronology is when you find the "J" in text[i], you want to use another loop to push the rest of your name into the empty array named hits using push method.

So based on your code, correction should be made for:

  1. console.log(myName) is unnecessary.
  2. you have an incomplete for loop for(var j = i; how to end the loop? when (<myName.length+i) ...... complete the rest
  3. after having a complete condition for loop, what code should you run?
    (push the rest of your name into hits)
    hits.push( ....?.... )

Hope this may give you a good lead. :slight_smile:


#3

I had someone else help with the code, but thanks anyway!


#4

Mind to share your code here? Did you get it passed? :slight_smile:


#5

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