Please help


#1


var text = "this is big felix program felix"
var myName = "felix";
var hits =[]
for (var i = 0; i < text.length ; i++);{
if(text[i] === "f");
for (var f=i; f < i+myName.length; i++){
hits.push(text[f]}


Replace this line with your code.


#2

Hi there Felix,

In future posts it might be helpful for you to let us know the specifics of the problem you are having (e.g. error messages, descriptive title), as well as to format your code:

var text = "this is big felix program felix"
var myName = "felix";
var hits =[]

for (var i = 0; i < text.length ; i++); {
	if(text[i] === "f");
	for (var f=i; f < i+myName.length; i++) {
		hits.push(text[f]
	}

First, may I suggest you check out this post on when to use and not use semicolons to make sure you are not ending your loops prematurely (such as if or for statements for example)?

In addition to the semicolons, now that your code has some space around it, do you notice that you are missing some opening and closing curly braces and parentheses? For example, do you think the last if and for statements should be on the same level? Or should one be indented? If so, is something missing?

Finally, in the last for statement, you declare a variable f and set it to < (i + myName.length); to prevent an endless loop, but then increment variable i. Regarding this I have for you some food for thought:

  • if we i++ in the f for loop, do you think the program will stop adding to i when i < text.length? Or will it loop infinitely?
  • Furthermore, why declare f at all?

I hope this helps. Please let me know if you have more questions.

frisby