javascript - Animate random number generator onclick -


i'm new java , javascript bare me. have script once clicking button generate random number between 0 , 13. i'd add kind of animation when button clicked looks it's working each time. such flashing other random numbers each time before settling on it's final number, simular dice. javascript code have far generate random number this;

function newnumber() { var x = math.floor((math.random() * 14) + 0); document.getelementbyid("number").innerhtml = x; } 

what best way go this?

much example: http://jsfiddle.net/zdsma/1/ not broken that

thank you

for future reference if else trying figure out same:

function newnumber() {     var x = math.floor((math.random() * 14) + 0);     document.getelementbyid("dice").innerhtml = x;       var output, started, duration, desired;  // constants duration = 1000;   // initial setup output = $('#dice'); started = new date().gettime();  // animate! animationtimer = setinterval(function() {     // if value want, stop animating     // or if duration has been exceeded, stop animating     if (output.text().trim() === desired || new date().gettime() - started > duration) {         clearinterval(animationtimer);     } else {         console.log('animating');         // generate random string use next animation step         output.text(             ''+             math.floor((math.random() * 14) + 0)         );     } }, 100);   } 

*requires jquery


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -