accessing local variables within another function
<p>Here is the code I have written:</p>

<pre><code>function p_deal(id) {
    var card1_val = Math.floor(Math.random() * deck.length);
    var card2_val = Math.floor(Math.random() * deck.length);
        var card1 = deck[card1_val];
        var card2 = deck[card2_val];
    var hand = card1 + ", " + card2;
var res = card1_val + card2_val;

document.getElementById(id).innerHTML = hand;
</code></pre>

<p>and</p>

<pre><code>function hit(id) {
    if (bucket == 0) {
        bucket = " ";
    }

    var card3_val = Math.floor(Math.random() * deck.length);
    var nhand = deck[card3_val];
    bucket = bucket + " " + nhand + ", ";
    bucket_val = bucket_val + card1_val + card2_val + card3_val;

    if (bucket_val &gt;= 22) {
        var r = confirm("Bust! By " + nhand);
        if (r == true) {
            refresh();
        }
        else {
            refresh();
        }
    }

    document.getElementById(id).innerHTML = bucket;

    light = light + 1;

    if (light == 5) {
        alert("Five Card Blackjack! You Win!");
        refresh();
    }
}
</code></pre>

<p>The card_val variables within bucket val are from the p_deal(id) function. In order for the program to work, the card_val values must be the <strong>same</strong> each time both functions are called but they need to be regenerated each time the function is called (so multiple players can have different hands). However, as local variables I find it difficult to use them in another function.  What can i do here?</p>
