Problem with code


#1

What's wrong?
jshint multistr:true
var text = "adfkjadf k;alkdjf ;alkdsfj 93ruailsejfk a;lsdkfj aeiru a;kj devorah asdkfje4\
lskdfj devorah asdlkfj39uf alkdjfe9fj alkdjf ejfdika devorah as;dlfk";
var myName = "devorah";
var hits = [];
for (i=0; i<=text.length; i++) {
if (text[i] === 'd') {
for(j=i;j<(myName.length+i);j++){
hits.push(text[j])
}
}
}

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


#2

@deesilby,

Syntax

for ([initialization]; [condition]; [final-expression]) {
   statement
}

The only flaw i see, is the condition in your 1st FOR-loop
which should be

i < text.length

#3

@deesilby,
You could change the code

var text = "adfkjadf k;alkdjf ;alkdsfj 93ruailsejfk a;lsdkfj aeiru a;kj devorah asdkfje4\
lskdfj devorah asdlkfj39uf alkdjfe9fj alkdjf ejfdika devorah as;dlfk";
var myName = "devorah";
var hits = [];
for (i=0; i<text.length; i++) {
 if (text[i] === 'd') {
     for(j=i;j<(myName.length+i)&& j<text.length;j++){
        hits.push(text[j]);
     }
     hits.push("======");
 }
}

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

#4

changed the condition and its still giving me an error message.. can you explain what you changed in the code?