前进的方向是什么 [英] What is the way forward

查看:148
本文介绍了前进的方向是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i am supposed to  write a card counting function that It will receive a card parameter, which can be a number or a string, and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player's decision (Bet or Hold) should be separated by a single space.









但代码似乎没有运行,我被告知必须这样做:





but the code doesn't seem to run,am being told that this must be done:

Cards Sequence 2, 3, 4, 5, 6 should return 5 Bet
Cards Sequence 7, 8, 9 should return 0 Hold
Cards Sequence 10, J, Q, K, A should return -5 Hold
Cards Sequence 3, 7, Q, 8, A should return -1 Hold
Cards Sequence 2, J, 9, 2, 7 should return 1 Bet
Cards Sequence 2, 2, 10 should return 1 Bet
Cards Sequence 3, 2, A, 10, K should return -1 Hold





我尝试了什么:





What I have tried:

var count = 0;

function cc(card) {
  // Only change code below this line
  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    count += 1;
    break; 
    case 7:
    case 8:
    case 9:
    count += 0;
    break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
    count -= 1;
    break;
  }
  
  return count + (count == 0 ? "5 Bet": "Hold");
  // 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');

推荐答案

引用:

我应该写一个卡计数功能,它会收到一个卡参数,可以是数字或字符串

i am supposed to write a card counting function that It will receive a card parameter, which can be a number or a string





为什么当你把它复杂化时,它会变得简单吗?

你使用数字或字符串作为卡片面值,除了价值本身之外没有其他原因。每张卡的处理方式相同,无论它的价值如何,你都不会对数值进行算术运算。

这些是数字:1,2,3,10。

那些atr字符串:1,2,3,10。

你可以使所有卡面值成为字符串。



"Why makes it simple when you can make it complex ?"
You are using numbers or strings as card face values for no other reasons than the value itself. Each card is handled the same, no matter of it value, you are not doing arithmetic on numeric values.
Those are numbers: 1, 2, 3, 10.
Those atr strings: "1", "2", "3", "10".
you can make all card face values strings.

引用:

但代码似乎没有运行



不要猜,请确认。您的浏览器有一个开发人员控制台,允许您查看JS错误消息。

-----

您的代码行为不符合您的预期,或者您不喜欢理解为什么!



有一个几乎通用的解决方案:逐步在调试器上运行代码,检查变量。

调试器是这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它不知道您的代码应该做什么,它没有发现错误,只是通过向您展示正在发生的事情来帮助您。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。



调试器 - 维基百科,免费的百科全书 [ ^ ]


掌握调试Visual Studio 2010 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]



JavaScript调试 [< a href =https://www.w3schools.com/js/js_debugging.asptarget =_ blanktitle =New Window> ^ ]

Chrome DevTools  | 网络  |  Google Developers [ ^ ]



这里的调试器只显示你的代码正在做什么,你的任务是与它应该做什么进行比较。


Don't guess, make sure. Your browser have a developer console witch allow you to see JS error messages.
-----
Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

JavaScript Debugging[^]
Chrome DevTools  |  Web  |  Google Developers[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.


这篇关于前进的方向是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆