Turn-based game setting properties for playcards I am programming with Java (server side) and JavaScript a card game and I do not know how to give properties (on server side) to every card that I create. For a match I need 20 different cards from a complete set of cards (52). Now I want that these 20 cards get a value (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King) and a symbol (like Spades, Hearts, Diamonds and Clubs).

How should I approach this? I thought using if clauses like I used on client side would be ok (JavaScript):

p.initialize = function (id) {

this.card= new createjs.Bitmap(images[id]);

// HEARTS
if (id &gt; 0 &amp;&amp; id &lt; 14)
{
this.symbol = Card.HEARTS;
}

// DIAMONDS
else if (id &gt; 13 &amp;&amp; id &lt; 28)
{
this.symbol = Card.DIAMONDS;
}

// CLUBS
else if(id &gt; 27 &amp;&amp; id &lt;42)
{
this.symbol = Card.CLUBS;
}

// SPADES
else if(id &gt; 41 &amp;&amp; id &lt;53)
{
this.symbol = Card.SPADES;
}

this.VALUE = id%13;
};


This is the way I did it on client side. Should I do the same with Java or are there better possibilities?
Slight improvements of your current code


Get rid of the comments and read three lines below which symbol you are currently declaring the conditions for. Your code is very self-documenting, no need to add comments.
You should know that there is a more than or equal to operator, which can be used to make your code a lot more readable (here I have also removed the braces since your statement is only one line) 

if (id &gt;= 1 &amp;&amp; id &lt;= 13) this.symbol = Card.HEARTS;
else if (id &gt;= 14 &amp;&amp; id &lt;= 28) this.symbol = Card.KARO;
else if (id &gt;= 28 &amp;&amp; id &lt;= 41) this.symbol = Card.CLUBS;
else if (id &gt;= 42 &amp;&amp; id &lt;= 52) this.symbol = Card.SPADES;



This can in turn also be simplified to:

    if (id &lt;= 0) { /* mega-super-error-should-probably-not-happen-and-if-it-does-then-it's-no-symbol */ }
    else if (id &lt;= 13) this.symbol = Card.HEARTS;
    else if (id &lt;= 28) this.symbol = Card.KARO;
    else if (id &lt;= 41) this.symbol = Card.CLUBS;
    else if (id &lt;= 52) this.symbol = Card.SPADES;


Weird King

Are you aware that in your current code, you will have the values 1 2 3 4 5 6 7 8 9 10 11 12 0? This feels weird. If Ace is 1 then 0 is king I assume? But using 0 as king does not make sense.

Adding a parameter to the function

Even though @rolfl provides a short way to do this, I just want to object to one thing: The use of the id parameter.

It seems like you are creating a card from an ID. Now what if you some day totally forget about how to calculate these IDs from a specified suite and rank? (or vice versa). I would instead use a function with two parameters: Suite and rank. I'm not sure how you are calling this method today, but to me it feels cleaner to create cards by using a nested for-loop to loop first over suite and then over rank, rather than looping from 1 to 52.

Also, I wouldn't use an uppercase property VALUE when the others, symbol and card is lowercase. It's better to use lowercase value also. Or, you could call it rank instead. And you might want to rename the card property to picture.

As for how to do it in Java, I would say that you should try to make it the same in both Java and JavaScript. Tidy up the JavaScript and then make it the same in Java.