I can't find what I'm doing wrong! Help plz! (lesson number 5)


#1

/*jshint multistr:true */
var text = "Hi there, I'm Ben. Do you find my name intriguing or is Ben a normal name?
var myName = "Ben"
var hits = []
for( i = 0; i <= text.length; i++) {
if (text[i] === 'B'){ for(var j = i; j > i + text.length; j++)}}
hits.push(text[j])

This is my code and I don't find what I did wrong (probably al lot but still)
If you could help me that would be appreciated!

-SpookyCommando


#2

Hi this part

for(var j = i; j > i + text.length; j++)

Here j > i + text.length change the > to <
Its shouldn't be text.length but myName.length like that

for(var j = i; j < i + myName.lenght; j++)

#3

It still doesn't work.

/*jshint multistr:true */
var text = "Hi there, I'm Ben. Do you find my name intriguing or is Ben a normal name?
var myName = "Ben"
var hits = []
for( i = 0; i <= text.length; i++) {
if (text[i] === 'B'){ for(var j = i; j > i + myName.length; j++)}}
hits.push(text[j])

This is my code so far but now it outputs: SyntaxError: Unexpected EOF


#4

In this code the error is here

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

This part j > i + myName.length; you should put j < I myName.length; like that

for(var j = i; j < i + myName.length; j++)

And the hits.push should be inside the last for loop


#5

like this? : ar text = "Hi there, I'm Ben. Do you find my name intriguing or is Ben a normal name?
var myName = "Ben"
var hits = []
for( i = 0; i <= text.length; i++) {
if (text[i] === 'B'){ for(var j = i; j < i + myName.length; j++){
hits.push(text[j])}
}
}


#6

Yes its should be like that , ... did it work?


#7

Nope still the same error :confused: (SyntaxError: Unexpected EOF)


#8

Hi make some change to your first for loop instead of i <= text.length try to put i < text.length ` so your code should be like that

var text = "Hi there, I'm Ben. Do you find my name intriguing or is Ben a normal name?"
var myName = "Ben"
var hits = []
for( i = 0; i < text.length; i++) {
    if (text[i] === 'B'){ 
        for(var j = i; j < i + myName.length; j++){
            hits.push(text[j])}
}
}

You forgot to close your var text " " string


#9

Ok that's a really stupid thing to do and now it's fixed! Just by closing my text var :stuck_out_tongue: thank you very much friend!


#10

Your welcome I'm glad that I could help
Happy coding :smile: