#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    23
    Rep Power
    0

    Problem using push method with array


    I can't figure out what's wrong with my .push statement.
    It is adding the object to the array regardless of the condition.

    My code is supposed to pick a random card and display it in a popup window, which it does, but the array is always 150 cards even if my 6 player forms show these cards as 'collected', and out of the deck (array)

    I'll only show the code for card 1 (south africa) to keep the code short.

    Code:
    function picked_cashcard_popup(){
    
    var cash_cards = new Array("136","137","138","139","140","141","142","143","144","145","146","147","148","149","150");
    // Cards 136-150 ALWAYS have to be in deck (they are not collectable - 1 through 135 ARE collectable.
    
    <!------south_africa - checked variables---------->
    if (player_1_form.south_africa_travel_voucher_cashcard.checked  == true)
    south_africa_p1_checked = true;//not checked
    else
    south_africa_p1_checked = false;//checked
    alert(south_africa_p1_checked);
    
    //My push statement, where the problem seems to be
    if (south_africa_p1_checked == true && 
    south_africa_p2_checked == true && 
    south_africa_p3_checked == true && 
    south_africa_p4_checked == true && 
    south_africa_p5_checked == true && 
    south_africa_p6_checked == true);
    	cash_cards.push("1");
    
    alert(cash_cards);		
    
    <!------ extra shuffling, until I find a better method------>						
    var shuffled = cash_cards.sort( function() { return Math.random() - 0.9 } );
    var shuffled2 = shuffled.sort( function() { return Math.random() - 0.1 } );
    var shuffled3 = shuffled2.sort( function() { return Math.random() - 0.6 } );
    var shuffled4 = shuffled3.sort( function() { return Math.random() - 0.3 } );
    var shuffled5 = shuffled4.sort( function() { return Math.random() - 0.8 } );
    var shuffled6 = shuffled5.sort( function() { return Math.random() - 0.5 } );
    var shuffled7 = shuffled6.sort( function() { return Math.random() - 0.2 } );
    var shuffled8 = shuffled7.sort( function() { return Math.random() - 0.7 } );
    var shuffled9 = shuffled8.sort( function() { return Math.random() - 0.4 } );
    var shuffled_length = (shuffled9.length);
    
    alert(shuffled_length);
    
    alert(shuffled9);
    
    var picked_card = shuffled9[Math.floor(Math.random()*cash_cards.length)]
    
    alert(picked_card);
    
    
    
    var newwindow=window.open("","",config="height=380,width=450,left=10,top=200,resizable=0");
    		newwindow.document.writeln("<html>\n<head>\n<title>CASH CARD DRAW</title>\n<link rel='stylesheet' type='text/css' href='travelbarons.css'>\n</head>");
    		newwindow.document.writeln("<body bgcolor='#000000' vlink='Silver' link='#FF0000'><center>\n<img src='images/cash/cashcard_" + picked_card + ".jpg' width='340px' height='220px' align='absmiddle'><br><br>\n");
    		newwindow.document.writeln("<img src='images/sweet.jpg' align='absmiddle'><br><br>");
    		newwindow.document.writeln("<img src='images/sweet_2.jpg' align='absmiddle'><br>");
    		newwindow.document.writeln("<a href='' onclick='self.close();'><img src='images/close_button.png' align='absmiddle' border='0'></a></center>\n</body>\n</html>");
    }
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,141
    Rep Power
    9398
    You have a semicolon immediately after the conditions. It's a no-op.

IMN logo majestic logo threadwatch logo seochat tools logo