100 Days of Code: Day 13

Home / Technology / Web Development / 100 Days of Code: Day 13
I learned something new today about JavaScript! I also tackled the rest of the Basic Javascript section on freeCodeCamp and dove right into the Programming Foundations course on Lynda.com.

[vc_row css=”.vc_custom_1526680382655{margin-top: 15px !important;margin-bottom: 60px !important;padding-right: 10% !important;padding-left: 10% !important;}”][vc_column][vc_progress_bar values=”%5B%7B%22label%22%3A%22Progress%22%2C%22value%22%3A%2213%22%2C%22color%22%3A%22blue%22%7D%5D” title=”100 Days of Code, Round 1″ percentage_value=”27″ title_color=”#3e3e3e” bar_color=”#1b7da9″ track_height=”20px” track_color=”#e7f6fc” m=”20″ extra_class=”” units=”%”][/vc_column][/vc_row][vc_row][vc_column][vc_custom_heading text=”Goals For Today:” font_container=”tag:h3|text_align:left” use_theme_fonts=”yes”][ultimate_icon_list icon_size=”16″ icon_margin=”20″][ultimate_icon_list_item icon_type=”custom” icon_img=”id^4091|url^https://www.blissfullemon.com/wp-content/uploads/2018/05/done.png|caption^null|alt^null|title^done|description^null”]Finish the ‘Basic JavaScript‘ section in freeCodeCamp[/ultimate_icon_list_item][ultimate_icon_list_item icon_type=”custom” icon_img=”id^4091|url^https://www.blissfullemon.com/wp-content/uploads/2018/05/done.png|caption^null|alt^null|title^done|description^null”]Watch a few of the Programming Foundations: Fundamentals videos from Lynda.com[/ultimate_icon_list_item][ultimate_icon_list_item icon_type=”custom” icon_img=”id^4093|url^https://www.blissfullemon.com/wp-content/uploads/2018/05/incomplete.png|caption^null|alt^null|title^incomplete|description^null”]Start on Day #1: Portfolio website from 30 Days, 30 Sites challenge[/ultimate_icon_list_item][/ultimate_icon_list][vc_custom_heading text=”The Good:” font_container=”tag:h3|text_align:left” use_theme_fonts=”yes”][vc_column_text]Celebration gif

I LEARNED SOMETHING NEW!

I spent a bit of time working on JavaScript objects (and properties). To be completely honest, I don’t remember ever using objects in JavaScript before. I knew you could, but I just don’t recall having ever done it. It’s a bit different from creating classes in other OOP languages like VB.NET, C# and Java. So, I think I have officially learned something new.[/vc_column_text][vc_custom_heading text=”The Bad:” font_container=”tag:h3|text_align:left” use_theme_fonts=”yes” el_class=”clear”][vc_column_text]I gave myself a little bit too much to do today. It would have been fine except for the fact that: a) I was really tired so it took twice as long to do anything during the first 2+ hours, and b) I didn’t expect to run into something new today, so the Basic JavaScript section took longer to finish than I originally anticipated.

Tomorrow, I will work on my time-management. And make some coffee.[/vc_column_text][vc_custom_heading text=”Notes/Comments:” font_container=”tag:h3|text_align:left” use_theme_fonts=”yes”][vc_column_text]

Using Dot Notation vs. Bracket Notation With Object Properties

The way that it is explained at freeCodeCamp, dot notation is used to access/modify properties of an object when the property is only one word (ex. myObject.name).

Bracket notation, on the other hand, is used when the property is more than one word (ex. myObject[“first name”]) or when you are using a variable to access the property (ex. myObject[varFName]).

Okay, that sounds simple enough, but I wondered why even bother with dot notation in the first place if bracket notation basically had all the bases covered to begin with?

So, of course, me being who I am, I did some research and it seems to be that the general consensus is to use dot notation (if you can) because it’s faster. Not only is it just faster to type, but it also allows you to access the property faster because you are essentially turning the property name into a string when you use bracket notation, but with dot notation that isn’t necessary.[/vc_column_text][vc_row_inner css=”.vc_custom_1526941270663{margin-right: 75px !important;margin-left: 75px !important;}”][vc_column_inner width=”1/6″][vc_icon icon_fontawesome=”fa fa-commenting-o” color=”custom” size=”lg” custom_color=”#ffdd00″][/vc_column_inner][vc_column_inner width=”5/6″][vc_column_text]If you have a better explanation or something more to add (or correct, for that matter), please let me know. I love learning new things, and I would certainly prefer to know if there is a better explanation.[/vc_column_text][/vc_column_inner][/vc_row_inner][vc_column_text]

Counting Cards

One of the freeCodeCamp challenges today was about using nested if/else statements to create a little card counting assistant. I decided to share my solution below since you can access the full solution from them anyway (so I am not really giving anything away).

var count = 0;

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

     var instruction = "";

     if (card >= 2 && card <=6) {

          count++;

          if (count > 0) {
               instruction = " Bet";
          } else {
               instruction = " Hold";
          }

          return count + instruction;

     } else if (card > 6 && card < 10) {

          if (count > 0) {
               instruction = " Bet";
          } else {
               instruction = " Hold";
          }

          return count + instruction;

     } else if (card == 10 || card == "J" || card == "Q" || card == "K" || card == "A" ) {

          count--;

          if (count > 0) {
               instruction = " Bet";
          } else {
               instruction = " Hold";
          }

          return count + instruction;

     } else {

          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');

[/vc_column_text][/vc_column][/vc_row]

Let's chat!

%d bloggers like this: