6/7 Log It! Unexpected Else Statement


#1

Help! Tell me what's wrong with my code:
/*jshint multistr:true */
var text = "I love the name Brian. The name Brian is cool. I'm a nice guy named Brian."
var myName = "Brian"
var hits = []
hits.push('My name is in Text once/another time.');
for (var i = 0; i >= text.length; i++) {
if (text[i] === 'B') {
for (var j = i; j >= i + myName.length; i++) {
hits[0];
console.log(hits);
}
else {
console.log("Your name wasn't found!");
}
}
}
I got: Unexpected else statement


#2

I noticed my mistake.


#3

Thats great but you still have a little bit to correct logically here


#4

Wait so what am I supposed to do? I changed my code to this:
/*jshint multistr:true */
var text = "I love the name Brian. The name Brian is cool. I'm a nice guy named Brian."
var myName = "Brian"
var hits = []
hits.push('My name is in Text once/another time.');
for (var i = 0; i >= text.length; i++) {
if (text[i] === 'B') {
for (var j = i; j >= i + myName.length; i++) {
console.log(hits[0]);
}
else {
console.log("Your name wasn't found!");
}
}
}
Basically I logged hits[0]. But it now says Unexpected Else Statement!


#5

Take a look at this post perhaps it will give you an idea what to do
CLICK HERE TO POST

your for loop condition is wrong

and if your code were to move to this for loop

You would be stuck in an infinite loop


#6

Yeah. I tried it, and I'm still confused. Sorry, I am only 9! :neutral_face:


#7

This is my current code:
/*jshint multistr:true */
var text = "I love the name Brian. The name Brian is cool. I'm a nice guy named Brian."
var myName = "Brian"
var hits = [];
for(var a=0 ; a if(text[a]=== myName[0]){
for(var b=a ; b<(a + myName.length) ; b++){
hits.push(text[b]);
}
}