4.0 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
565bbe00e9cc8ac0725390f4 Counting Cards 1 计数卡

Description

在赌场游戏Blackjack中玩家可以通过跟踪牌组中剩余的高牌和低牌的相对数量来获得优势。这称为卡计数 。在牌组中剩下更多高牌有利于玩家。根据下表为每张卡分配一个值。当计数为正数时,玩家应该下注。当计数为零或负数时,玩家应该下注低。
计数变化
+1 2,3,4,5,6
0 7,8,9
-1 10'J''Q''K''A'
你会写一个卡计数功能。它将接收一个card参数,可以是数字或字符串,并根据卡的值递增或递减全局count变量(参见表格)。然后,该函数将返回一个包含当前计数的字符串,如果计数为正则返回字符串Bet ,如果计数为零或为负,则返回Hold 。当前计数和玩家的决定( BetHold )应该由一个空格分隔。 示例输出
-3 Hold
5 Bet 提示
当值为7,8或9时请勿将count重置为0。
不要返回数组。
不要在输出中包含引号(单引号或双引号)。

Instructions

Tests

tests:
  - text: 牌序列<code>5 Bet</code>应该返回<code>5 Bet</code>
    testString: 'assert((function(){ count = 0; cc(2);cc(3);cc(4);cc(5);var out = cc(6); if(out === "5 Bet") {return true;} return false; })(), "Cards Sequence 2, 3, 4, 5, 6 should return <code>5 Bet</code>");'
  - text: '卡片序列7,8,9应返回<code>0 Hold</code>'
    testString: 'assert((function(){ count = 0; cc(7);cc(8);var out = cc(9); if(out === "0 Hold") {return true;} return false; })(), "Cards Sequence 7, 8, 9 should return <code>0 Hold</code>");'
  - text: 卡序列10JQKA应返回<code>-5 Hold</code>
    testString: 'assert((function(){ count = 0; cc(10);cc("J");cc("Q");cc("K");var out = cc("A"); if(out === "-5 Hold") {return true;} return false; })(), "Cards Sequence 10, J, Q, K, A should return <code>-5 Hold</code>");'
  - text: '卡序列3,7Q8A应返回<code>-1 Hold</code>'
    testString: 'assert((function(){ count = 0; cc(3);cc(7);cc("Q");cc(8);var out = cc("A"); if(out === "-1 Hold") {return true;} return false; })(), "Cards Sequence 3, 7, Q, 8, A should return <code>-1 Hold</code>");'
  - text: 牌序列2J <code>1 Bet</code>应该返回<code>1 Bet</code>
    testString: 'assert((function(){ count = 0; cc(2);cc("J");cc(9);cc(2);var out = cc(7); if(out === "1 Bet") {return true;} return false; })(), "Cards Sequence 2, J, 9, 2, 7 should return <code>1 Bet</code>");'
  - text: 牌序列<code>1 Bet</code>应该返回<code>1 Bet</code>
    testString: 'assert((function(){ count = 0; cc(2);cc(2);var out = cc(10); if(out === "1 Bet") {return true;} return false; })(), "Cards Sequence 2, 2, 10 should return <code>1 Bet</code>");'
  - text: '卡序列3,2A10K应返回<code>-1 Hold</code>'
    testString: 'assert((function(){ count = 0; cc(3);cc(2);cc("A");cc(10);var out = cc("K"); if(out === "-1 Hold") {return true;} return false; })(), "Cards Sequence 3, 2, A, 10, K should return <code>-1 Hold</code>");'

Challenge Seed

var count = 0;

function cc(card) {
  // Only change code below this line


  return "Change Me";
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Solution

// solution required