areyouhappynow
10-09-2005, 09:34 AM
This code uses a nested IF statement to put a pack of cards into an array of records.
But for some reason the cards arn't going in.. like.. at all?
I've put a document.write piece of code at end to display the card in the first slot and [object Object] appears?
<HTML>
<TITLE>DAT Card Game</TITLE>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var Cards = new Array (52)
var Shuffled = new Array (52)
function Card(suit,face)
{this.suit=suit;
this.face=face;
}
function Stack(suit,face)
{
var suit
var face
index=0
count=1
for (count=1;count<=52;count++)
if (count<=39)
{if (count<=13)
{suit='hearts'
face=count
Cards[index]=new Card(suit,face)
index++
count++}
else
{if (count<=26)
{suit='spades'
face=count
Cards[index]=new Card(suit,face)
index++
count++}
else
{if (count<=39)
{suit='diamonds'
face=count
Cards[index]=new Card(suit,face)
index++
count++}}}}
else
{suit='clubs'
face='count'
Cards[index]=new Card(suit,face)
index++
count++}
document.write(Cards[0])
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="MyForm">
<INPUT TYPE="BUTTON" VALUE="stack" onClick="Stack()">
</FORM>
</BODY>
</HTML>
If you copy and paste into notepad and then look at it in your browser you'd see what I mean.
Any ideas?
EDIT: I think my syntax for creating An Array Records is totally wrong just looking through tutorials. Each object in the array has to have a name?
EDIT 2: Ignore this post. I've given up on the Object in Array structure.
But for some reason the cards arn't going in.. like.. at all?
I've put a document.write piece of code at end to display the card in the first slot and [object Object] appears?
<HTML>
<TITLE>DAT Card Game</TITLE>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var Cards = new Array (52)
var Shuffled = new Array (52)
function Card(suit,face)
{this.suit=suit;
this.face=face;
}
function Stack(suit,face)
{
var suit
var face
index=0
count=1
for (count=1;count<=52;count++)
if (count<=39)
{if (count<=13)
{suit='hearts'
face=count
Cards[index]=new Card(suit,face)
index++
count++}
else
{if (count<=26)
{suit='spades'
face=count
Cards[index]=new Card(suit,face)
index++
count++}
else
{if (count<=39)
{suit='diamonds'
face=count
Cards[index]=new Card(suit,face)
index++
count++}}}}
else
{suit='clubs'
face='count'
Cards[index]=new Card(suit,face)
index++
count++}
document.write(Cards[0])
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="MyForm">
<INPUT TYPE="BUTTON" VALUE="stack" onClick="Stack()">
</FORM>
</BODY>
</HTML>
If you copy and paste into notepad and then look at it in your browser you'd see what I mean.
Any ideas?
EDIT: I think my syntax for creating An Array Records is totally wrong just looking through tutorials. Each object in the array has to have a name?
EDIT 2: Ignore this post. I've given up on the Object in Array structure.