how to combine a do while loop and setInterval timer function
<p>I am trying to simulate a dice roll by combining a do while loop and a setInterval function.</p>

<p>the goal is this: user clicks dice roll button. they view a series of numbers and then the roll stops and returns a value.</p>

<p>my idea was to use the 'do while' loop to control how many iterations occur before the dice stops ‘rolling’. i’ve tried a few different things but nothing has worked so far. my latest attempt is below.</p>

<pre><code>function diceRoll(){
    theNum = Math.floor(Math.random() * 6) + 1; 
    counter = counter + 1;
    console.log(theNum);
    console.log(counter);
}

$(document).ready(function(){
    counter = 1;
    myVar = '';
    $('#start').click(function(){
        do {
        //
        myVar = setInterval(function(){ diceRoll() }, 500);
        } while (counter &lt; 10)
    });
</code></pre>