Can't figure out .push


#1


I seem to beat this exersive because of the.push


/*jshint multistr:true */
var text = "blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah natha blah blah blah blah blah blah blah";
var myName = "natha"
var hits = []

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



#2

It's wrong condition, should be:

if(text[i] === myName[0]) {...}
// or
if(text[i] === 'n' {...}

Next here:

for(var j=i;j>myName.length+i;j++) {...}

Here you also have wrong condition. Symbol 'n' is at 85 position, so:

for(var j=85; 85 > 5 + 85; j++) {...}

85 > 5 + 85; this statement defines the condition for running the loop, so should be j < myName.length+i;


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.