Edit in JSFiddle

(function() {
  /* HTML DOM */
  let demo = document.getElementById("demo");
  let message = demo.getElementsByTagName("pre")[0];
  let draw = demo.getElementsByTagName("button")[0];
  let pass = demo.getElementsByTagName("button")[1];

  /* constants */
  let ACTOR = {
    PLAYER: 0,
    COMPUTER: 1
  };
  let turn = ACTOR.PLAYER;

  /* variables */
  let player_card = [];
  let computer_card = [];
  let player_pass = false;
  let computer_pass = false;
  let game_endding = false;

  /* AI */
  let ai = function() {
    /* define variables */
    const pass = 0, draw = 1;                         // A
    let U = Array.from({length: 2}, () =>             // utility, s = (c, f)
            Array.from({length: 16}, () => 0));       // |c| = 16, |f| = 2 
    let Ut = Array.from({length: 2}, () =>            // utility temp.
             Array.from({length: 16}, () => 0));      // size same with |U|   
    let D = Array.from({length: 2}, () =>             // decision table
             Array.from({length: 16}, () => 0));      // size same with |U|  
    let epsilon = 0.01;                               // iterative stop para.
    let gamma = 0.9;                                  // discount factor
    let delta;                                        // iterative diff. for step

    /* reward function */
    let R = function(c) {
      return c > 10 ? 0 : c;
    };

    /* expected value of action
       f = 0: can select "pass" only (exp = [pass_value])
       f = 1: can select "draw" or "pass" (exp = [pass_value, draw_value]) */
    let Exp = function(c, f) {
      let exp = [];
      if (f == 0) {                                   // f = 0: pass only
        exp.push(1.0 * R(c));                         // pass: 100%
      } else if (f == 1) {                            // f = 1: pass or draw
        exp.push(1.0 * R(c));                         // pass: 100%
        let t = 0;                                    // draw: now point + 1~5 (20%)
        for (let d = 1; d <= 5; d++) {
          if (c + d < 16) {
            t += 0.2 * U[f][c + d];
          }
        }
        exp.push(t);
      }
      return exp;                                     // return expected value
    };

    /* algorithm main */
    do {
      for (let f = 0; f <= 1; f++) {                  // copy utility temp
        for (let c = 0; c <= 15; c++) {
          U[f][c] = Ut[f][c];
        }
      }
      delta = 0;                                      // initialize delta for step
      for (let f = 0; f <= 1; f++) {                  // for all s = (c, f)
        for (let c = 0; c <= 15; c++) {
          let exp = Exp(c, f);
          Ut[f][c] = R(c) + gamma * Math.max(...exp); // Bellman's equation

          /* create decision table */
          if (exp.length == 1 || exp[0] >= exp[1]) {  // max function choose "pass"
            D[f][c] = 0;
          } else {                                    // max function choose "draw"
            D[f][c] = 1;
          }
          if (Math.abs(Ut[f][c] - U[f][c]) > delta) { // calc. max delta
            delta = Math.abs(Ut[f][c] - U[f][c]);     // save delta
          }
        }
      }
    } while (delta >= epsilon * (1 - gamma) / gamma); // condition for stop
    return D; 																				// return decision table
  };

  /* get ai decision */
  let decision = ai()[1];

  /* card sum */
  let sum = function(cards) {
    return cards.length > 0 ? cards.reduce((p, c) => p + c) : 0;
  };

  /* game initialize */
  let initialize = function() {
    player_card = [];
    computer_card = [];
    player_pass = false;
    computer_pass = false;
    game_endding = false;
  };

  /* check winner */
  let check = function(a, b) {
    if (a > 10 && b > 10) {
      return 2;
    } else if (a > 10 && b <= 10) {
      return ACTOR.COMPUTER;
    } else if (a <= 10 && b > 10) {
      return ACTOR.PLAYER;
    } else {
      if (player_pass) {
        if (a < b) {
          return ACTOR.COMPUTER;
        } else if (a > b) {
          return ACTOR.PLAYER;
        } else if (a == b) {
          return 2;
        }
      }
    }
    return -1; //not endding
  };

  /* game main-loop */
  let next_turn = function() {
    let a = sum(player_card);
    let b = sum(computer_card);
    message.innerHTML = `玩家的牌面是:`;
    player_card.forEach((card, index) => {
      message.innerHTML += `${card}${index != player_card.length - 1 ? "," : ""}`;
    });
    message.innerHTML += ` (${a}, ${player_pass ? "pass": "draw"})`;
    message.innerHTML += `\n電腦的牌面是:`;
    computer_card.forEach((card, index) => {
      message.innerHTML += `${card}${index != computer_card.length - 1 ? "," : ""}`;
    });
    message.innerHTML += ` (${b}, ${computer_pass ? "pass": "draw"})`;
    if ((player_pass && computer_pass) || a > 10 || b > 10) {
      let winner = check(a, b);
      switch (winner) {
        case ACTOR.PLAYER:
          message.innerHTML += `\n玩家贏了,按 Draw 重新開始`;
          break;
        case ACTOR.COMPUTER:
          message.innerHTML += `\n電腦贏了,按 Draw 重新開始`;
          break;
        case 2:
          message.innerHTML += `\n平手,按 Draw 重新開始`;
          break;
      }
      game_endding = (winner != -1);
    }
  };

  let computer_draw = function() {
    if (computer_pass == false) {
      let b = computer_card.length > 0 ? computer_card.reduce((p, c) => p + c) : 0;
      if (decision[b] == 1) {
        let card = Math.floor(Math.random() * 100) % 5 + 1;
        computer_card.push(card);
        if (player_pass) {
          computer_draw();
        }
      } else {
        computer_pass = true;
      }
    }
  };

  draw.onclick = function() {
    if (game_endding) {
      initialize();
    }
    if (!player_pass) {
      let card = Math.floor(Math.random() * 100) % 5 + 1;
      player_card.push(card);
      computer_draw();
      next_turn();
    }
  };

  pass.onclick = function() {
    if (!game_endding) {
      player_pass = true;
      computer_draw();
      next_turn();
    }
  };
})();
<div id="demo">
  <pre></pre>
  <button>Draw</button>
  <button>Pass</button>
</div>
body {
  color: #ffffff;
  background: #20262e;
  font-family: monospace, sans-serif;
}

#demo input {
  width: 120px;
  color: #ffffff;
  background: #20262e;
  border: none;
  border-bottom: solid 1px #ffffff;
  outline: none;
}

#demo input {
  margin-right: 5px;
}

#demo button {
  cursor: pointer;
  color: #ffffff;
  background: #20262e;
  border: 1px solid #ffffff;
  outline: none;
}

#demo button:hover {
  color: #20262e;
  background: #ffffff;
}