"Pick the card" game with javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
itconnect
Forum Newbie
Posts: 2
Joined: Sun Jun 22, 2008 11:46 pm

"Pick the card" game with javascript

Post by itconnect »

Once the deck there will be a card placed showing its value and another three cards placed upside i.e. their value are hidden. One and only one of three cards has its value same as the first card.

The player will simply guess the card containing the right value from the three cards and click it. If the clicked card has the value player will be awarded one point. If not awarding value will be zero. In this way having finished 10 rounds the game is over and cumulative score will be shown.
Sample javascript code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script language="javascript" type="text/javascript">

var check=false;
var score=0;
var currentScore = 0;
var timer;
var ROUND=1;
var rndCount;
var rndCount1;
var rndCount2;
var rndCount3;
var chars = "JKQT";
var string_length = 1;
var randomstring = '';
var randomstring1 = '';



function randomString() {
var chars = "JKQT";
//var string_length = 8;
var string_length = 1;
var randomstring = '';
var randomstring1 = '';
var ROUND=1;
var score=0;

//var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";

for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
//document.randform.randomfield.value = randomstring;
document.randform.btn.value = randomstring;
rndCount=document.randform.btn.value;


}
function randomStringBtn1(counter) {

var chars = "JKQT";
//var string_length = 8;
var string_length = 1;
var randomstring = '';

for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}

//document.randform.randomfield.value = randomstring;
document.randform.btn1.value = randomstring;
rndCount1=document.randform.btn1.value;

//return rndCount1;
}

function randomStringBtn2() {
var chars = "JKQT";
//var string_length = 8;
var string_length = 1;
var randomstring = '';
var randomstring1 = '';

//var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";

for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
//document.randform.randomfield.value = randomstring;
document.randform.btn2.value = randomstring;
rndCount2=document.randform.btn2.value;


}
function randomStringBtn3() {
var chars = "JKQT";
//var string_length = 8;
var string_length = 1;
var randomstring = '';
var randomstring1 = '';

//var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";

for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
//document.randform.randomfield.value = randomstring;
document.randform.btn3.value = randomstring;
rndCount3=document.randform.btn.value;
}



</script>


</head>

<body onload="randomString()">
<br><br>
<form name="randform">
<div id="score">
ROUND: &nbsp;<input readonly name="roundfield" type="text" size="10" value="" maxlength="10" > <br>
SCORE: &nbsp;&nbsp;<input readonly name="randomfield" type="text" size="10" value="" maxlength="10" >


<center>


<input type="button" name="btn" value=" " style="WIDTH: 90px; HEIGHT: 90px" size=57/><br><br><br>
<input type="button" name="btn1" value=" " onclick="randomStringBtn1()" style="WIDTH: 90px; HEIGHT: 90px" size=57/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="btn2" value=" " onclick="randomStringBtn2()" style="WIDTH: 90px; HEIGHT: 90px" size=57/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" name="btn3" value=" " onclick="randomStringBtn3()" style="WIDTH: 90px; HEIGHT: 90px" size=57/>

<!--<input type="text" name="randomfield" value="">-->
</form>
</div>
</center>

</body>
</html>

Please help me to complete the game...
User avatar
ghurtado
Forum Contributor
Posts: 334
Joined: Wed Jul 23, 2008 12:19 pm

Re: "Pick the card" game with javascript

Post by ghurtado »

Please wrap your code in [ code ] tags so that your post will be readable
Post Reply