+ 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++; }

21st Nov 2017, 9:35 AM
horcrux88
horcrux88 - avatar
1 ответ
+ 5
Change to i++; i= i++; would make i always stay at same value, no increment happened.
21st Nov 2017, 9:50 AM
Calviղ
Calviղ - avatar