Advertisement
flomath

blub

Mar 9th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. text = "Florian haljlabjalk Florian dsl FOGEL kfjsakfj skajfl as Florian djlfaj";
  2.  
  3. var myName = "Florian";
  4. var hits = [];
  5.  
  6. // Look for "E" in the text
  7. for(var i = 0; i < text.length; i++) {
  8.     if (text[i] === myName[0]) {
  9.         // If we find it, add characters up to
  10.         // the length of my name to the array
  11.         for(var j = i; j < (myName.length + i); j++) {
  12.     hits.push(text[j]);
  13.             }
  14.        
  15.     }
  16. }
  17.  
  18. if(hits.length===0){
  19.  console.log("Your name wasn't found!");  
  20. } else console.log(hits);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement