Throws three dice. Each with a different random value between 1 and 6. use only first or both as required in your game!

Two dice at a time Press any key or press the button to throw. Another implementation is here
 
|



sel2in.com
Code snippet:

function startDice(){
	document.getElementById('btn1').disabled = true;

	chngcnt++;
	if(chngcnt > chngchars1.length)chngcnt = 1;
	document.getElementById("chng").innerHTML = chngchars1.substring(0, chngcnt);
	var odice = document.getElementById("dice");
	odice.innerHTML = "-" ;
	//var timeoutID = setTimeout(dorand2, 400 + (60 * getRandomInt(1, 6)) );
	var timeoutID = setTimeout(dorand2, 1 + (3 * getRandomInt(1, 6)), 1, "");
}

function endDice(){
	document.getElementById('btn1').disabled = false;
}

function dorand2(w, s){
	document.getElementById("chng").innerHTML = '';
	var odice = document.getElementById("dice");

	var r1 = (getRandomInt(1, 6000) % 6) + 1;
	if(w < 3){
		if(w == 1){
			s = "Dice A : " + r1
		}else{
			s +=  "      Dice B : " + r1;
		}
		w++;
		var timeoutID = setTimeout(dorand2, 160 + (64 * getRandomInt(1, 3)) + (getRandomInt(95, 373)), w, s);
	}else{		
		odice.innerHTML =  s + "      Dice C : " + r1;
		endDice();
	}
}

function getRandomInt(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}


(c) 2017 Tushar Kapila.


v 2