jokerjumper18
08-29-2010, 08:46 AM
I'm trying to make a higher or lower game but I can't seem to get the higher and lower buttons to work. I have my deck set up in an array such as
var deck = [
{picture: "images/AceHearts.png", facevalue: 1 },
{picture: "images/2Hearts.png", facevalue: 2 },
etc.
]
<!-- Then the rest of my code is as follows>
function rnd()
{
return Math.random()-0.5;
}
function hidemessage(){
document.getElementById("winningmessage").style.display = "none";
}
hand1 = new Array();
deck.sort(rnd);
<!-- This function randomly picks a card and takes its value and returns it --!>
function getHandHTML(hand)
{
html= "";
total = 0;
for (i=0; i<hand.length; i++)
{
html+= "<img src = \""+ hand[i].picture +"\"> ";
total= hand[i].facevalue;
}
return html;
}
<!-- This function takes a card from the deck --!>
function nextcard()
{
for (i=0; i< 1; i++)
{
card = deck.shift();
hand1.push(card);
}
document.getElementById('hand1').innerHTML = getHandHTML(hand1);
document.getElementById("winningmessage").style.display = "none";
}
<!-- This function adds takes the next card from the deck and places it on the screen --!>
<!--It also disables the buttons after 6 cards have been drawn --!>
function addCardToHand()
{
card = deck.shift();
if (card == null) { return;}
hand1.push(card);
document.getElementById('hand1').innerHTML = getHandHTML(hand1);
if(i==6){
document.getElementById("higher").disabled = true;
document.getElementById("lower").disabled = true;
document.getElementById("winningmessage").style.display = "block";
}
}
window.onload = nextcard;
function higher(){
if (hand1[index].facevalue() > hand1[index-1].facevalue())
{
alert("higher");
}
else
{
alert("wrong")
}
}
</script>
<body>
<style>
.hand {margin: 20px; padding: 20px;}
</style>
<input type = button value = "higher" onclick = "addCardToHand();higher()" id = higher>
<input type = button value = "lower" onclick = "addCardToHand()" id = lower>
<div class = hand id = hand1></div>
<div id = "winningmessage">
You Win
</div>
</body>
</html>
I've highlighted the area where I've attempted to make an alert box pop up saying if the higher button was right or wrong.
Any suggestions would be much appreciated
var deck = [
{picture: "images/AceHearts.png", facevalue: 1 },
{picture: "images/2Hearts.png", facevalue: 2 },
etc.
]
<!-- Then the rest of my code is as follows>
function rnd()
{
return Math.random()-0.5;
}
function hidemessage(){
document.getElementById("winningmessage").style.display = "none";
}
hand1 = new Array();
deck.sort(rnd);
<!-- This function randomly picks a card and takes its value and returns it --!>
function getHandHTML(hand)
{
html= "";
total = 0;
for (i=0; i<hand.length; i++)
{
html+= "<img src = \""+ hand[i].picture +"\"> ";
total= hand[i].facevalue;
}
return html;
}
<!-- This function takes a card from the deck --!>
function nextcard()
{
for (i=0; i< 1; i++)
{
card = deck.shift();
hand1.push(card);
}
document.getElementById('hand1').innerHTML = getHandHTML(hand1);
document.getElementById("winningmessage").style.display = "none";
}
<!-- This function adds takes the next card from the deck and places it on the screen --!>
<!--It also disables the buttons after 6 cards have been drawn --!>
function addCardToHand()
{
card = deck.shift();
if (card == null) { return;}
hand1.push(card);
document.getElementById('hand1').innerHTML = getHandHTML(hand1);
if(i==6){
document.getElementById("higher").disabled = true;
document.getElementById("lower").disabled = true;
document.getElementById("winningmessage").style.display = "block";
}
}
window.onload = nextcard;
function higher(){
if (hand1[index].facevalue() > hand1[index-1].facevalue())
{
alert("higher");
}
else
{
alert("wrong")
}
}
</script>
<body>
<style>
.hand {margin: 20px; padding: 20px;}
</style>
<input type = button value = "higher" onclick = "addCardToHand();higher()" id = higher>
<input type = button value = "lower" onclick = "addCardToHand()" id = lower>
<div class = hand id = hand1></div>
<div id = "winningmessage">
You Win
</div>
</body>
</html>
I've highlighted the area where I've attempted to make an alert box pop up saying if the higher button was right or wrong.
Any suggestions would be much appreciated