var rand2, rand; var n = 0; for (var i=0; i<100; i++) { rand = Math.floor(Math.random() * 6);if(rand2==rand)n++; rand2=rand} alert(n);