By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,154 Members | 1,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,154 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";
  2.  
  3. var myName = "jospaht";
  4.  
  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++){
  10.  
  11.      hits.push("jospaht");
  12.  
  13.     }
  14. }
  15.  
Aug 12 '15 #1
Share this Question
Share on Google+
1 Reply


Dormilich
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.