Game How to ?

How to Play Ludo Game Without The Dice

Friends, today I have come up with a very silly Ludo game trick which is known to everybody but nobody knows how to implement it. Ludo is a very famous game played in many countries. Who does not like the snake ladder game, the great moment when you fall down after being eaten up by snake but your opponent is going up through the ladder.

Anyway, lets go to the real scenario when the Ludo board is with you but the dice are missing. All of you know dice are the integral part of Ludo game. What to do, how to play ?
I am with a solution.


 

Give me the Code

Don’t worry, the code has been made for you only. Be cool. Copy and Paste the following code in a notepad and save as .html extension.
<script type="text/javascript">
var counter=0;
function generateRandom(){
var num=1+Math.floor(Math.random()*6)
if(counter%2==0){
document.getElementById("result").innerHTML= num;
document.getElementById("result").style.color = 'Red';
}
else{
document.getElementById("result").innerHTML= num;
document.getElementById("result").style.color = 'Green';
}
counter++;
}
</script>
<div id="result" style="font-size:100px"></div>
<input type="button" onClick="generateRandom()" value="Throw" style="width:70px; height:70px;font-size:20px;">

Next time if the dice are missing no need to make saddy face, just get a cup of coffee and open this in your browser and throw the dice.

Heart of the code
The code is so simple that even a 5 year child can understand. 
Hey, remember no credit goes to me. It’s the Math.random()*6 which does everything. It is the heart of the program.

Bye, see you next time with more interesting articles.

Leave a Reply

Your email address will not be published. Required fields are marked *