I am very new to javascript and I have a little problem.
As my first "project", I want my program to give me a random poker card. Nothing to great, but I'm trying to figure out an elegant way to do it. By now my only idea is to give a random number between 1 and 52 a specific card, but there got to be a better way.
Here is my current code :
function newCard() {
var card_id = document.getElementById("card_id");
var c1 = Math.floor(Math.random() * 52) + 1;
switch(c1) {
case 1:
c1 = "ace of spades";
break;
case 2:
c1 = "2 of spades";
break;
case 3:
c1 = "3 of spades";
break;
// ...I think you get the idea here
}
card_id.innerHTML = c1;
}
Do you have a hint for me, how to make this quicker/better ?