1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | var deck = ["A", "A", "A", "A", 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, "J", "J", "J", "J", "Q", "Q", "Q", "Q", "K", "K", "K", "K"]; /*var deal = function (){ var n = (Math.ceil(Math.random() * deck.length)); return deck.splice(n, 1); };*/ var sum = function (card){ if (card.length <=2){ A = 11; } else{ A = 10; } J = 10; Q = 10; K = 10; var point = card[0]; for (i = 0; i < card.length - 1; i++){ point = point + card[i + 1]; } return point; }; var testing01 = [A, K]; var p1name = prompt("Please enter the name of Player 1."); var p2name = prompt("Please enter the name of Player 2."); //dealing stage if (confirm(p1name + ", press OK to deal card.")){ var p1card = []; p1card[0] = deal(); p1card[1] = deal(); //alert("Your card: " + p1card.toString() + "\nPoint: " + sum(p1card)); console.log(p1card + "AAA"); console.log(sum(testing01) + "BBB"); console.log(sum(p1card) + "CCC"); } /*if (confirm(p1name + ", press OK to deal card.")){ var p1c1 = deal(); //abbreviation: p1c1 = player1card1... var p1c2 = deal(); var p1card = [p1c1, p1c2]; alert("Your card: " + p1card.toString() + "\nPoint: " + sum(p1card)); } if (confirm(p2name + ", press OK to deal card.")){ var p2c1 = deal(); var p2c2 = deal(); var p2card = [p2c1, p2c2]; alert("Your card: " + p2card.toString()); } //p1 calling for more cards if (confirm(p1name + ", do you want to deal another card?\nYour card: " + p1card.toString())){ var p1c3 = deal(); p1card[2] = p1c3; alert("Your card: " + p1card.toString()); } if (confirm(p1name + ", do you want to deal another card?\nYour card: " + p1card.toString())){ var p1c4 = deal(); p1card[3] = p1c4; alert("Your card: " + p1card.toString()); } if (confirm(p1name + ", do you want to deal another card?\nYour card: " + p1card.toString())){ var p1c4 = deal(); p1card[4] = p1c4; alert("Your card: " + p1card.toString()); } //p2 calling for more cards if (confirm(p2name + ", do you want to deal another card?\nYour card: " + p2card.toString())){ var p2c3 = deal(); p2card[2] = p2c3; alert("Your card: " + p2card.toString()); } if (confirm(p2name + ", do you want to deal another card?\nYour card: " + p2card.toString())){ var p2c4 = deal(); p2card[3] = p2c4; alert("Your card: " + p2card.toString()); } if (confirm(p2name + ", do you want to deal another card?\nYour card: " + p2card.toString())){ var p2c4 = deal(); p2card[4] = p2c4; alert("Your card: " + p2card.toString()); }*/ //compare stage |
Direct link: https://paste.plurk.com/show/1428695