Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with card game

    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?

    thx

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    you can pass in a variable as a parameter for the number of cards like so:

    pigerCartes(p_numberOfCards)


    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •