For loop Javascript your if statement


#1



it says Syntax error; unexpected token


/*jshint multistr:true */
var text = "Hey, how are you Vaughan?\
How was your sleep Vaughan?\
My name is Vaughan?";

var myName = "Vaughan"

var hits = []

for (var i = 0; i < text.length ; i++;){
    if (myName[0] === "V")
    console.log (myName)
}


#2

As you can tell by the winkie emoticon, you need to move your semi-colon outside of the )


#3

you don't need a semicolon after stating the increment (i++), but after the others you do

also,

should be text[0] or text[i]

@bibleman13, i'm pretty sure that moving the semicolon to after the closing parenthesis would keep the for loop from actually parsing :wink: :stuck_out_tongue:


#4

In my code, nothing happened like that. I got bibleman on the screen and it passed so idk


#5

YOU ARE RIGHT! I just tried it, and it worked fine, but i'm not sure why. i guess maybe i don't understand JS that well. sorry for the correction. both ways work, (either removing it or moving it to outside of the parenthesis), but i don't know if there's a difference.

anyways, my bad. :slight_smile:


#6

Perfect all sorted just don't understand the second part


#7

Just try after var hits = [] to put ;
I think that will solve your problem :smiley:


#8

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