Advertisement
Guest User

Untitled

a guest
May 5th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. /*jshint multistr:true */
  2.  
  3. var text = "This is a string of Samantha text that says Samantha in it three times because Samantha.";
  4.  
  5. var myName = "Samantha";
  6.  
  7. var hits = [];
  8.  
  9. for (var i = 0; i >= text.length; i++)
  10. {
  11. if (text[i] === "S")
  12. {
  13. for (var j = i; j === myName.length; ????)
  14. }
  15. };
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. Your second "for" loop
  23.  
  24. Okay! Last loopy step: add another for loop, this time inside the body of your if statement (between the if's {}s).
  25.  
  26. This loop will make sure each character of your name gets pushed to the final array. The if statement says: "If we find the first letter of the name, start the second for loop!" This loop says: "I'm going to add characters to the array until I hit the length of the user's name." So if your name is 11 letters long, your loop should add 11 characters to hits if it ever sees the first letter of myName in text.
  27.  
  28. For your second for loop, keep the following in mind:
  29.  
  30. First, you'll want to set your second loop's iterator to start at the first one, so it picks up where that one left off. If your first loop starts with
  31.  
  32. for(var i = 0; // rest of loop setup
  33.  
  34. your second should be something like
  35.  
  36. for(var j = i; // rest of loop setup
  37.  
  38. Second, think hard about when your loop should stop. Check the Hint if you get stuck!
  39.  
  40. Finally, in the body of your loop, have your program use the .push() method of hits. Just like strings and arrays have a .length method, arrays have a .push() method that adds the thing between parentheses to the end of the array. For example,
  41.  
  42. newArray = [];
  43. newArray.push('hello');
  44. newArray[0]; // equals 'hello'
  45.  
  46. Instructions
  47.  
  48. Okay! Go ahead and add that second for loop inside the body of your if statement
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement