Today was just another heads down coding type of day. Which I want to be normal part of my daily life. Not to much to report on today. Still in the JavaScript Basics section of the course just 75% done.

I got to see cool ways to use JavaScript and its datasets. I liked how I was able to see a use case and movie reference to 21 about counting cards to win blackjack. I would like to add, I saw it in my high school math class. Most likely to make us think math was cool. Which I am not against, getting the youth to think technology is cool is great for advancement in any country. Like in Russia tech interest among women is high due to their early exposure to it. The perception is that it’s just normal for women to be in tech in Russia.

On to the card counting example in freecodecamp. This was the data you were given.

Count ChangeCards
+12, 3, 4, 5, 6
07, 8, 9
-110, ‘J’, ‘Q’, ‘K’, ‘A’

The problem was to write a switch function to count the cards and to either “Bet” or “Hold” depending on the outcome.

  • If the final count is 1 or greater, return # Hold.
  • If the final count is 0 or less, return # Bet.

The code performance:

  • Check the value of each card via a switch statement.
  • The variable count:
    • Increases by 1 if the card is a 2, 3, 4, 5, or 6.
    • Since 7, 8, and 9 aren’t worth anything, we ignore those cards in our switch statement.
    • Decreases by 1 if the card is a 10, ‘J’, ‘Q’, ‘K’, or ‘A’.

The code solution:

switch(card){
        case 2:
        case 3:
        case 4:
        case 5:
        case 6:
          count++;
          break;
        case 10:
        case "J":
        case "Q":
        case "K":
        case "A":
          count--;
          break;
      }
      if (count > 0){
        return count + " Bet";
      } else {
        return count + " Hold";
      }

This example led to think about other ways to use data sets like this. It was great to see more examples of using JavaScript. I am enjoying learning about JavaScript each day.

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: