Where have i gone wrong in my code?


#1



Replace this line with your code. 
/*jshint multistr:true */
var text="I am jay, i am a good jay";
var myName="jay";
var hits=[];
for(var i=0; i<myName.length;i++)
{
      if(text[i] === "j")
      {
          for(var j=i; j<i+myName.length;j++)
          
              hits.push(text[j]);
          
      }
      
}


#2

HI just try to refresh the page..


#3

it says"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."


#4

it's because in your first for loop you should loop through text instead of myName

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

#5

You are also missing some brackets... (@wizmarco at least I think I saw it right this time :joy:)


#6

this is what i have

var text="I am jay, i am a good jay";
var myName="jay";
var hits=[];
for(var i=0; i{
if(text[0] === "j")
{
for(j=i;j hits.push(text[j]);
}

}


#7

ohh i need to use (`)


#8

ohh i need to use (`)

Yesss :slight_smile:

And make sure to open and close all braces and parentheses.


#9

Yes but curly brackets can be omit.. :smile:

var num = 2
if (num === 3)
   console.log("Hello");
else
   console.log("Welcome")

you can read more about it here


1. If/else Unexpected token else
#10

I know, but I think here it's better not to :slight_smile:

Thank you for the link. I will be sure to read it now. :nerd:


#11

( `var text="I am jay, i am a good jay";
var myName="jay";
var hits=[];
for(var i=0; i{
if(text[0] === "j")
{
for(j=i;j hits.push(text[j]);
}

}
)


#12


#13

@jay8978 why use a for loop if you will only test one character? :wink:


#14

@msfrisby @wizmarco can you pls help seeing my picture above?


#15

@jay8978 Saw the pic, can you pls see my post above? :slight_smile: Remember, haste makes waste :sunglasses:


#16

if (text[0] === "j")//wrong
if (text[i]==="j")//right

@jay8978