By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,843 Members | 1,481 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,843 IT Pros & Developers. It's quick & easy.

What is the problem with my code

P: 1
Hi please help me fix this code. it is not bahaving as it should. what have I missed? This loop will make sure each character of my name gets pushed to the final array.

Expand|Select|Wrap|Line Numbers
  1. var text= "jospaht jospaht jospaht \ jospaht jospaht jospaht jospaht jospaht\ jospaht jospaht jospaht";
  3. var myName = "jospaht";
  5. var hits= [];
  6. for( var i=0;i<text.length;i++){
  7. }
  8. if(text[i]==="j"){
  9.     for(var i=0;i<i+myName.length;i++){
  11.      hits.push("jospaht");
  13.     }
  14. }
Aug 12 '15 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 8,639
you close the loop before you start the condition.
Aug 12 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.