# Random Poker card

## Recommended Posts

Hi everyone,

I am trying to find source or tutorial how to create the random. I will like to learn how to create the random in poker card, but i need to make sure it must show the display that card is used. For example, I click on back of card to draw card, then show number or royal on card, then click it, moved to left-top or right-top to keep tracking those random poker card...do you have any idea? those card can't be repeated.

Thank you so much

##### Share on other sites

Here is a basic text example of a random card draw...

```<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<title>Cards</title>
<script>

function init(){
document.getElementById('btn1').onclick = drawc;
document.getElementById('btn2').onclick = shuffle;
}

var str = "";
var cards = ['Ace','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Jack','Queen','King'];
var cardcount = suit.length * cards.length;
var facecount = cards.length;
var i = 0;

function drawc() {
var n;
var f;
var c;

if (i >= cardcount){
return;
}

do{
f = Math.floor(facecount * Math.random());
n = Math.floor(4 * Math.random());
c = cards[f] + ' of ' + suit[n];
}while(str.indexOf(c) != -1);
i++;
str = i + ' ' + c + '<br/>' + str;
document.getElementById("out1").innerHTML = str;
}

function shuffle(){
document.getElementById("out1").innerHTML = "";
str = "";
i = 0;
}
</script>

<body>

<p>Click the button to display a random card.</p>
<button id="btn1">Draw Card</button>
<button id="btn2">Shuffle Cards</button><br/><br/>
<div id="out1"></div>

</body>
</html>
```

##### Share on other sites

Oh cool, it worked, it is in JavaScript, right? Can i make an image in this script? But why i get "undefine of shade", "undefine of heart"...I will like to remove this "undefine"

Thanks!

Edited by Sigmahokies

##### Share on other sites

I'm sure you can find many sets of card images if you search the web. You deleted the joker. See the revised code above.

## Create an account

Register a new account