Your first "for" loop


#1

For some reason my page keeps crashing (infinite loop). Its probably something tiny that im doing wrong but i cant seem to find it. Any help is appreciated.

/*jshint multistr:true */
var text = "Hey, how are you doing? My name is Marco.";
var myName = "Marco";
var hits = [""];

for (var i = 0; i < text.length; i =+ 1){

};


#2

Ended up being really easy. I changed the order of the =+ and it worked. If the statement doesnt increment it produces an infinite for loop which results in a chrash. Final code would be:

/*jshint multistr:true */
var text = "Hey, how are you doing? My name is Marco.";
var myName = "Marco";
var hits = [""];

for (var i = 0; i < text.length; i += 1){

};

#3

Thanks this solved my problem too! :slight_smile: