How to access variables within another function
<p>I'm writing code for a blackjack game and have run into some problems. I have written two functions: one for the initial deal and one for each consecutive hit. this is the deal function:</p>

<pre><code>var deck = [1,2,3,4,5,6,7,8,9,10,"Jack","Queen","King","Ace"];

function deal() {
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;

{//card1 Conditionals
if (card1 == "Jack") {
    card1_val = 10;
    }
else if (card1 == "Queen") {
    card1_val = 10;
    }
else if (card1 == "King") {
    card1_val = 10;
    }
else if (card1 == "Ace") {
    card1_val = 11;
    }
}

{//card2 Conditionals
if (card2 == "Jack") {
    card2_val = 10;
    }
else if (card2 == "Queen") {
    card2_val = 10;
    }
else if (card2 == "King") {
    card2_val = 10;
    }
else if (card2 == "Ace") {
    card2_val = 11;
    }
}

var res = card1_val + card2_val;
document.getElementById("result").innerHTML = hand;
//document.getElementById("test").innerHTML = card1_val + ", " + card2_val;

if (res &gt; 21) {
    alert("Blackjack!");
    }
}
</code></pre>

<p>This is the hit function:</p>

<pre><code>function hit() {
var card_val = Math.floor(Math.random() * deck.length);
var nhand = deck[card_val];
bucket = hand + nhand
}
</code></pre>

<p>If you look at hit() I am using the var hand from deal(). I can't make it global because I need the value to be a fresh random each time. How do I access this same variable without rewriting lines of code? Any help would be appreciated.</p>
