Skip to main content
ugh, wrong while condition...
Source Link
jmar777
  • 39.8k
  • 11
  • 68
  • 66

Edit: more complete solution, and fixed off-by-one error:

var prev, randNumber; for(var i = 0; i < noBoxes.length; i+=randNumber) { do { randNumber = 2 + Math.floor(Math.random() * 4); } while(randNumber !===== prev); prev = randNumber; } 

Edit: more complete solution, and fixed off-by-one error:

var prev, randNumber; for(var i = 0; i < noBoxes.length; i+=randNumber) { do { randNumber = 2 + Math.floor(Math.random() * 4); } while(randNumber !== prev); prev = randNumber; } 

Edit: more complete solution, and fixed off-by-one error:

var prev, randNumber; for(var i = 0; i < noBoxes.length; i+=randNumber) { do { randNumber = 2 + Math.floor(Math.random() * 4); } while(randNumber === prev); prev = randNumber; } 
Source Link
jmar777
  • 39.8k
  • 11
  • 68
  • 66

Edit: more complete solution, and fixed off-by-one error:

var prev, randNumber; for(var i = 0; i < noBoxes.length; i+=randNumber) { do { randNumber = 2 + Math.floor(Math.random() * 4); } while(randNumber !== prev); prev = randNumber; }