5. Your second for loop HELP HELP!


#1


I don't know what's wrong with my code.
Please help!!!!!!

#2

Could you paste the code


#4

/*jshint multistr:true */
var text=" My name is Yan Lin. Today's weather is nice and hot. Yan Lin is me, and I'm Yan Lin. I like to play poker and watch movie."
var myName="Yan Lin"
var hits=[]

for (var i=0;i if (var text[i]==="Y"){
for (var j=i; j< i+myName.length ; j++){ hits.push
(text[j])}
}

}


#5

well, you forgot ALL the semicolons in your code...


#6

/*jshint multistr:true */
var text=" My name is Yan Lin. Today's weather is nice and hot. Yan Lin is me, and I'm Yan Lin. I like to play poker and watch movie."
var myName="Yan Lin"
var hits=[]

for (var i=0;i if (var text[i]==="Y"){
for (var j=i; j< i+myName.length ; j++:wink:{ hits.push
(text[j]:wink:};
};

};


#7

/*jshint multistr:true */
var text=" My name is Yan Lin. Today's weather is nice and hot. Yan Lin is me, and I'm Yan Lin. I like to play poker and watch movie."
var myName="Yan Lin"
var hits=[]

for (var i=0;i if (var text[i]==="Y"){
for (var j=i; j< i+myName.length ; j++ :wink:{ hits.push
(text[j] :wink:};
};

};


#8

It's ; where there's emjio. I don't what happen, but is it correct?


#9

Your code should not display emojis. Go back, check both of your for loops for syntax errors and make adjustments.

Can you copy and paste the code you currently have? The one in your first post seemed the most correct.


#10

And when pasting code, there is a button in the top bar that looks like </>, It will let you past your code so it looks like code. :slight_smile:


#11

/*jshint multistr:true */
var text=" My name is Yan Lin. Today's weather is nice and hot. Yan Lin is me, and I'm Yan Lin. I like to play poker and watch movie."
var myName="Yan Lin"
var hits=[]

for (var i=0;i<text.length;i++){ 
    if (var text[i]==="Y"){ 
        for (var j=i; j< i+myName.length ; j++;){ hits.push    
        (text[j];)};
     };
    
};

#12

You have a semicolon after j++ that needs to be removed. There are other parts of your code where the semicolons aren't useful or necessary.

This link may prove useful:

https://www.codecademy.com/blog/78-your-guide-to-semicolons-in-javascript


#13

I still can't find the problem.:confounded:

/*jshint multistr:true */
var text=" My name is Yan Lin. Today's weather is nice and hot. Yan Lin is me, and I'm Yan Lin. I like to play poker and watch movie."
var myName="Yan Lin"
var hits=[]

for (var i=0;i<text.length;i++)
{ 
    if (var text[i]==="Y")
    { 
        for (var j=i; j< i+myName.length;j++)
        { hits.push(text[j])}
     }    
}

#14

I don't think you can declare variables and assign values in a condition. Remember, the goal for this if condition is to trigger the execution of the 2nd loop.


#15

I got it !!!!! Thank you very much!!!!:slight_smile::thumbsup:


#16

Glad you worked it out :slight_smile:


#17

var text = "Hey, how are you \ doing? My name is Sravani.";
var myName = "Sravani";
var hits = [];
for(var i=0; i{
if(var text[i] === "S")
{
for(var j=1; j {
hits.push(text[j]);
}
}

}

can anyone help me!
it returns syntax error.


#18

Get rid of the var in front of the var text[i].


#19

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