21 game

You are encouraged to solve this task according to the task description, using any language you may know.
21 is a two player game, the game is played by choosing
a number (1, 2, or 3) to be added to the running total.

The game is won by the player whose chosen number causes the running total
to reach exactly 21.

The running total starts at zero.
One player will be the computer.

Players alternate supplying a number to be added to the running total.



Task

Write a computer program that will:

 do the prompting (or provide a button menu), 
 check for errors and display appropriate error messages, 
 do the additions (add a chosen number to the running total), 
 display the running total, 
 provide a mechanism for the player to quit/exit/halt/stop/close the program,
 issue a notification when there is a winner, and
 determine who goes first (maybe a random or user choice, or can be specified when the game begins). 


print "-----------------------------"
print " Welcome to 21 Game"
print "-----------------------------"
 
players: ["A" "B"]
currentPlayer: sample players
nextPlayer: first players -- currentPlayer
runningTotal: new 0
num: 0
 
getNum: function [][
    result: strip input "Enter a number (1,2,3) / x to exit: "
    if result="x" -> exit
    return result
]
 
loop.forever @[currentPlayer nextPlayer] 'plays [
    print ["Running total:" runningTotal]
    print ["Player" plays "turn"]
 
    num: getNum
 
    while [or? [not? numeric? num][not? contains? 1..3 to :integer num]][
        num: getNum
    ]
 
    runningTotal: runningTotal + to :integer num
 
    print ""
 
    if runningTotal=21 [
        print ["Running total is 21. Player" plays "won!"]
        exit
    ]
]
 