sentry3
|
  |
| Joined: 01 May 2010 |
| Total Posts: 538 |
|
|
| 31 Jul 2016 02:32 AM |
I know this is maybe not the place for this but there is a lot of smart people here so,
im trying to find a name in a variable
//sentence
var text = 'hello my name is Nick, to bad your \ name is not Nick';
//my name
var myName = 'Nick';
//array
var hits = [];
for (var i = 0; i < text.length; i++){ if (text[i] === myName){ for (var j = i; j + myName.length; j++){ hits.push(myName[j]); } } }
basically the error says 'It looks like your second 'for' loop isn't pushing values to the hits array. Make sure it's working properly and that myName's text appears somewhere in the text variable.' |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 02:41 AM |
| you put ' j + myName.length' instead of j < myName.length' |
|
|
| Report Abuse |
|
|
sentry3
|
  |
| Joined: 01 May 2010 |
| Total Posts: 538 |
|
|
| 31 Jul 2016 03:21 AM |
@Flux
Careful: your second 'for' loop should stop when it reaches its current point in the string + myName.length |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2016 03:33 AM |
| it will still never stop because any non-0 integer evaluates to true. |
|
|
| Report Abuse |
|
|