View Full Version : Need help with card game

05-08-2006, 01:43 AM
I need some help regarding a project of mine..

function pigerCartes(){

var zone = document.getElementById("divCartes");
var nbCartes = document.forms[0].menuNombre.selectedIndex;
var sorte = document.forms[0].menuSorte.selectedIndex;
var tCartes = [1,2,3,4,5,6,7,8,9,10,11,12,13];

zone.innerHTML = "";

for (var x = 0; x < tCartes.length; x++) {
var cheminCartes = "cartes_gif/" + sorte + "-" + (x+1) + ".gif";
zone.innerHTML += '<img src="' + cheminCartes + '"> ';

what this function does basically (for now) is take a look at the form in the html file and displays 13 cards of either spades hearts etc... But I have a menu that lets me select the number of cards I want displayed... and if, for example, I want to have only 3 spades displayed.. Well I just don't know how to do it.. i'm stuck .. I tried many different things and nothing's working..

Could someone tell me how I can make the function see what's the number of cards I want displayed and make it do the rest but with the number of cards in mind?


05-08-2006, 03:13 PM
you can pass in a variable as a parameter for the number of cards like so:


and then in your for loop instead of looping over all of them you loop until p_numberOfCards like so:

for (var i = 0; i < p_numberOfCards; ++i)

Good luck!