What is the problem with my code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • atepsey
    New Member
    • Aug 2015
    • 1

    What is the problem with my code

    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.

    Code:
    var text= "jospaht jospaht jospaht \ jospaht jospaht jospaht jospaht jospaht\ jospaht jospaht jospaht";
    
    var myName = "jospaht";
    
    var hits= [];
    for( var i=0;i<text.length;i++){
    }
    if(text[i]==="j"){
        for(var i=0;i<i+myName.length;i++){
          
         hits.push("jospaht");
        
        }
    }
    Last edited by atepsey; Aug 12 '15, 12:51 PM. Reason: To give an explanation on what I want to achieve with the code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you close the loop before you start the condition.

    Comment

    Working...