Basic JavaScript Day 3: Homework

Hi Lina,

I now looked closer at your code, and sorry for not pointing this out earlier, but your case returns a string regardless of the actual value of count. As the count variable lives in the global space, it will keep its value on each call to the function. So to solve this challenge successfully, you need to do this in 2 steps:

  1. Evaluate the card and add either +1, 0, -1 to the count variable
  2. Evaluate the count variable, and if it is positive, return the current count and Bet, otherwise return the current count and Hold

Some other tips:

  • note that you do not need to ‘add’ anything when the card is 7, 8 or 8 - so you could consider leaving these out of the ‘case’ evaluation, if:
  • you evaluate and return the solution outside of the switch (aka: use the switch to change count, return your function after the switch)
  • you can stop evaluating the card after you found its value as case - so it would be better to break; (but the last case evaluation does not need it as you are done anyways).

I hope this helps Lina. If you are still stuck - let me know and I will post a code sample.

3 Likes