math.randomseed(os.time())
local name = 1
local value = 2
local cardArray = {
    {"Two", 2},
    {"Three", 3},
    {"Four", 4},
    {"Five", 5},
    {"Six", 6},
    {"Seven", 7},
    {"Eight", 8},
    {"Nine", 9},
    {"Ten", 10},
    {"Jack", 10},
    {"Queen", 10},
    {"King", 10},
    {"Ace", 11}
}

local randomCard = math.random(1, 13)
local randomCard2 = math.random(1, 13)
local randomCard3 = math.random(1, 13)

local dealerRandom = math.random(1, 13)
local dealerRandom2 = math.random(1, 13)
local dealerRandom3 = math.random(1, 13)

local playerCard1 = cardArray[randomCard][name]
local playerCard2 = cardArray[randomCard2][name]
local playerCard3 = cardArray[randomCard3][name]

local playerCardValue1 = cardArray[randomCard][value]
local playerCardValue2 = cardArray[randomCard2][value]
local playerCardValue3 = cardArray[randomCard3][value]

local dealerCard1 = cardArray[dealerRandom][name]
local dealerCard2 = cardArray[dealerRandom2][name]
local dealerCard3 = cardArray[dealerRandom3][name]

local dealerCardValue1 = cardArray[dealerRandom][value]
local dealerCardValue2 = cardArray[dealerRandom2][value]
local dealerCardValue3 = cardArray[dealerRandom3][value]

local playerTotalValue = playerCardValue1 + playerCardValue2
local playerTotalValue2 = playerCardValue1 + playerCardValue2 + playerCardValue3
local dealerTotalValue = dealerCardValue1 + dealerCardValue2
local dealerTotalValue2 = dealerCardValue1 + dealerCardValue2 + dealerCardValue3

local function pHit()
    print("Your first card is ".. playerCard1 .. " with a value of ".. playerCardValue1)
    print("Your second card is ".. playerCard2 .. " with a value of ".. playerCardValue2)
    print("Your third card is ".. playerCard3 .. " with a value of ".. playerCardValue3)
    print("Your total value is ".. playerTotalValue)
end

local function dHit()
    print("Dealer's first card is ".. dealerCard1 .. " with a value of ".. dealerCardValue1)
    print("Dealer's second card is ".. dealerCard2 .. " with a value of ".. dealerCardValue2)
    print("Dealer's third card is ".. dealerCard3 .. " with a value of ".. dealerCardValue3)
    print("Dealer's total value is ".. dealerTotalValue)
end

local function phitStandFunction()
    if playerTotalValue < 11 then
        playerTotalValue = playerTotalValue2
        pHit()
    else
        print("Your first card is ".. playerCard1 .. " with a value of ".. playerCardValue1)
        print("Your second card is ".. playerCard2 .. " with a value of ".. playerCardValue2)
        print("Your total value is ".. playerTotalValue)
    end
end

local function dhitStandFunction()
    if dealerTotalValue < 11 then
        dealerTotalValue = dealerTotalValue2
        dHit()
    else
        print("Dealer's first card is ".. dealerCard1 .. " with a value of ".. dealerCardValue1)
        print("Dealer's second card is ".. dealerCard2 .. " with a value of ".. dealerCardValue2)
        print("Dealer's total value is ".. dealerTotalValue)
    end
end

local function winLossFunction()
    if playerTotalValue > dealerTotalValue and playerTotalValue == 21 then
        print("Player wins with Black Jack")
    elseif playerTotalValue == playerTotalValue2 and playerTotalValue > dealerTotalValue and dealerTotalValue == 21 then
        print("Player wins with 21")
    elseif playerTotalValue < dealerTotalValue and dealerTotalValue == 21 then
        print("Dealer wins with Black Jack")
    elseif dealerTotalValue == dealerTotalValue2 and playerTotalValue > dealerTotalValue and dealerTotalValue == 21 then
        print("Dealer wins with 21")
    elseif playerTotalValue > dealerTotalValue then
        print("Player wins ".. playerTotalValue .. " to ".. dealerTotalValue)
    elseif playerTotalValue < dealerTotalValue then
        print("Dealer wins ".. dealerTotalValue .. " to ".. playerTotalValue)
    elseif playerTotalValue == dealerTotalValue then
        print("Player pushes")
    else
        print("Error")
    end
end

phitStandFunction()
dhitStandFunction()
winLossFunction()

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: