5. Your second "for" loop


5. Your second "for" loop

I have no idea what to do and I am very confused. The page also becomes unresponsive. Please help.

/*jshint multistr:true */
var text = "bla bla bla bla bla bla Michael bla bla bla bla Michael"
var myName = "Michael"
var hits = ["Michael"];

for(var i = 0; i < text.length; i++){
    if(text[i] === myName[0]){
        for(var i = 0; i < myName.length; i++){


Your page becoming unresponsive on running your code suggests that you have an infinite loop, you would need to look closer at your conditions and anything that affects them. You may also want to observe rather than speculate, print out values that your conditions rely on to see whether they change the way you expect them to.


both for loops are using the variable i


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