Help with search for your name code, nothings getting pushed in the hits array


#1

/*jshint multistr:true */
var text = "Hello my name is Sel. I'm always asked where my/ parents got the name Sel, then i tell them its a family name. Every 5th male gets Sel as a name";
var myName = "Sel";
var hits = [];
for(var i=0; i if (text[i]==="S"){for(var j=i+myName.length; j<=i+myName.length; j++){
hits.push(j) }; }; };
it says: "make sure you're pushing letters to the hits array." but i can't figure where im going wrong.


#2

Explain to me please of how this is a for loop:

This is not how you are supposed to make a for loop, as you already should know. And, you must separate your two loops.

You have to add the location of where "i" is.

hits.push(____[i]);

Generally, you have a lot of syntax errors in your code, but let's do it step by step, shall we? So first make these corrections: Separate the for loop and your if loop. Change your hits.push function.


#3

hey it actually didn't copy and paste right this is what it looks like:

/*jshint multistr:true */
var text = "Hello my name is Sel. I'm always asked where my/ parents got the name Sel, then i tell them its a family name. Every 5th male gets Sel as a name";
var myName = "Sel";
var hits = [];
for(var i=0; i if (text[i]==="S"){for(var j=i+myName.length; j<=i+myName.length; j++){
hits.push(j) }; }; };


#4

/*jshint multistr:true */
var text = "Hello my name is Sel. I'm always asked where my/ parents got the name Sel, then i tell them its a family name. Every 5th male gets Sel as a name";
var myName = "Sel";
var hits = [];
for(var i=0; i if (text[i]==="S"){for(var j=i+myName.length; j<=i+myName.length; j++){
hits.push(text[i]); }; }; };

this came out correct but i don't see anything in the hits array


#5

/*jshint multistr:true */
var text = "Hello my name is Sel. I'm always asked where my/ parents got the name Sel, then i tell them its a family name. Every 5th male gets Sel as sur a name";
var myName = "Sel";
var hits = [];
for(var i=0; i if (text[i]==="S"){for(var j=i+myName.length; j<=i+myName.length; j++){
hits.push(text[i]); }; }; };

if (hits.length=0){
console.log("Your name wasn't found!"); }
else { console.log(hits); }

again same problem, the console.log comes out as [] with nothing in between.


#6

This is correct:
(Also your second post):

If you look at all the codes and compare them, you will see that they have this difference:

This is your correct one.

Your first one:

Your third one:

Get it?


#7

thanks!, i appreciate the help :smile: