For loop Javascript your if statement


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)


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


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


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:


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


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:


Perfect all sorted just don't understand the second part


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


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