+ 1

Enable Button after a function execution is completed.

I create two functions here. Inside rolldice() setDelayInterval() is called recursively (with setTimeout option). Now I want to Enable a button only after execution of setDelayInterval() is completed. Note: By simply adding enable button code after setDelayInterval() not working. function rolldice(){ // DISABLE BUTTON HERE var getImage = "https://bassemtodary.files.wordpress.com/2012/10/dice.png"; imgpath = document.getElementById('put-image'); var random_number = null; var minimum = 0; var maximum = 0; // Create Random coordinates var coordinate = ["0 0", "-220px 0", "220px 0", "0 -220px", "-220px -220px", "220px 220px"]; maximum = (coordinate.length)-1; //Delay loop execution setDelayInterval(maximum, minimum, getImage, coordinate, minimum); // ENABLE BUTTON AFTER EXECUTION OF ABOVE FUNCTION IS COMPLETE } function setDelayInterval(maximum, minimum, getImage, coordinate, i){ if(i <= maximum){ setTimeout(function () { var random_number = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; imgpath.style.background = "url("+getImage+")"+coordinate[random_number]; imgpath.style.width = "220px"; imgpath.style.height = "220px"; i++; setDelayInterval(maximum, minimum, getImage, coordinate, i); }, 200); } }

14th May 2017, 5:52 PM
Munish
Munish - avatar
1 Antwort
+ 6
i made changes to your code and added comments (code is private but accessible from here) watch lines 7, 37, 47 https://code.sololearn.com/W9cAuRbwMA4c/?ref=app [edit] deleted code changes can be observed at: https://code.sololearn.com/WGE682FI02Ku/?ref=app
14th May 2017, 6:20 PM
Burey
Burey - avatar