JSFiddle - React, Tailwind, and code Playground

by Julien MBA-NDONG

HTML

<div id="doStuff"> 
</div>

JavaScript

/**************  v4  *************/
var i = 0, xFriction = 0.01, idInterval = 0, xVelocity = 7;

/*var j=0;
do {
    xVelocity = xVelocity * (1 - xFriction) ;
    //var idInterval = window.setInterval(inc, 50);
    var idInterval = window.setTimeout(inc, 50);
    //xFriction += 0.01 ;
    console.log(xVelocity);
    j++;
} while ( xVelocity > 0.001 && j < 3000)

if ( false ){
    //window.clearInterval(idInterval);
    window.clearTimeout(idInterval);
    xFriction = 7;
}*/

// an alternative code to call de inc function
function inc(){ 
    
    //setTimeout(inc, 100);
    
    // Your inc code here
    i += 1; 
    document.getElementById("doStuff").innerHTML = i ;
}

//setInterval( function(){inc();}, 17);


//inc();