Just Do It

I’m one month down in my twelve month project (or at least I will be by the end of this post) and I’m moderately happy with my success. I’ve certainly written a good bit but I’m sure each post is unorganized and could be better edited. This is mostly due to the fact that I write each post on the last day of the week. This will improve as the year goes on and I have more to write about.


This week I finished the Javascript course with Codecademy. I wish there were more exercises to practice everything I’ve learned but I feel like I got a good base to build on. This course also exposed me to objects which is the core of this and other object oriented programming. In the coming weeks I hope to finish going through Stoyan Stefanov’s *Object-Oriented Javascript*. I also found a great link to a [List of Free Programming Books](http://resrc.io/list/10/list-of-free-programming-books) github project. It has books from practically every branch of programming. There are several for Javascript as well as jQuery and other js based foundations so I have plenty of reading to keep me busy.

Much of the Codecademy Javascript course was based on making simple browser based games to teach you the different tools available. Some were basic like a coin flip, and others more complicated adventure games. I want to try to recreate the dice game *Left, Right, Center* to practice Javascript. The game is made up of rolling specialized dice to keep or give away your chips, and the goal is the be the last one with any chips at the table. Instead of numbers the dice have and L, R, C, and three Dots. For each die rolled you do the action it requires, giving to your left opponent, your right opponent, the center pile, or keeping it if you roll a dot. When you are out of chips you could return to the game if someone has to give you a chip.

Here is what I have up to this point.

userChips = 3;
leftChips = 3;
rightChips = 3;
centerChips = 0;
var result = [];
function RollDice() {
    Dice = Math.floor(1 + Math.random() * 6);
    switch(Dice) {
        case 1:
          alert("You Rolled Left");
          return "left";
        case 2:
          alert("You Rolled Right");
          return "right";
        case 3:
          alert("You Rolled Center");
          return "center";
        case 4:
          alert("You Rolled a Pip");
          return "pip";
        case 5:
          alert("You Rolled a Pip");
          return "pip";
        case 6:
          alert("You Rolled a Pip");
          return "pip";
    } // close switch
  } // close RollDice

function myTurn() {
  for(i = 1; i <= 3 && i <= userChips; i++){
    switch(RollDice()) {
      case "left":
          userChips -= 1;
          leftChips += 1;
      case "right":
          userChips -= 1;
          rightChips += 1;
     case "center":
          userChips -= 1;
          centerChips += 1;
     case "pip":
    } // close switch
  } // close for loop
  if(result === ["pip", "pip", "pip"]) {
    userChips = userChips + centerChips;
    alert("You got all the center chips!");
  alert("userChips " + userChips);
  alert("leftChips " + leftChips);
  alert("rightChips " + rightChips);
  alert("centerChips " + centerChips);
} // close myTurn

It’s just a start and I’m probably going about things the wrong way, but the mistakes I make along the way will help me learn. I have to just do it. There’s no better way to learn.

Leave a Reply