+ 1
Javascript code keeps doing a loop
Why would this code keep looping in my browser? It is a tutorial question I am doing and I checked the answer, but it keeps looping in my browser. The browser keeps loading. var products = ['choc', 'mint', 'cake', 'bubblegum']; var hasBubbleGum = [false,false,false,true]; var i = 0; while(i < hasBubbleGum.length){ if (hasBubbleGum[i]){ console.log(products[i] + ' has bubblegum'); } i = i++; }
1 ответ
+ 5
Change to
i++;
i= i++; would make i always stay at same value, no increment happened.