Tuesday, July 21, 2015

Day 121: Back to the JavaScript Book, Chapter 39

So, to begin with, my pull request was accepted by the Odin Project this morning!  That means my Euler Problem solutions will now be listed as examples that other students can look at in case they get stuck and want some help or just want to look at ways to solve the problem other than what they came up with.  That's pretty sweet.

Moving on, I started the day on Chapter 39 of the JavaScript book, Switch Statements: How to Start Them.  The switch statements chapter started out by going over this code:

var dayOfWk = prompt("What day is it today?");
if (dayOfWk === "Sat" || dayOfWk === "Sun") {
  alert("Whoopee!");
}
else if (dayOfWk === "Fri") {
  alert("TGIF");
}
else {
  alert("Shoot me now!");
}


Which works fine.  But, according to this chapter, there is something called a switch statement which can be used to write this kind of code more elegantly.  With switch statements, there is no space after switch, and the second line, the one that starts with case, is not indented.  Further, the second line ends in a colon.  Here's an example:

var city = prompt("Enter your city to know if we offer our services there!");

switch(city) {
case "Akron" :
  alert("Yes, we do offer our services in Akron, please contact your local representative.");
  break;
case "Chicago" :
  alert("Unfortunately, we do not offer our services in Chicago yet, but if you would like to sign up for our newsletter, we can inform you as soon as we begin operations in Chicago.");
case "Tampa Bay" :
  alert("Unfortunately, we do not offer our services in Tampa Bay yet, but if you would like to sign up for our newsletter, we can inform you as soon as we begin operations in Tampa Bay, which will happen soon.");
  break;
default :
  alert("Unfortunately, your city is outside our current and near future area of coverage.");
}

The third line and every line thereafter, below each case, is indented two spaces.  At the end of each case, there is a break statement.  The last item is the default, which is not necessary, it's optional, and it does not need a break at the end, since there is no code below it to be stopped by a break.  The closing curly braces go at the end of the last case.

I finished Chapter 40 Switch Statements" How to Complete Them, and I'll start with chapter 41 While Loops tomorrow.
 
SUMMARY OF CODING SKILLS

Total Treehouse Points: 5,385

Treehouse Points by Subject Matter (Miscellaneous not included): 
HTML:                                663 
CSS:                                1,599 
Design:                            1,193 
Development Tools:            747 
Javascript:                      1,120

Treehouse Ranking (%): "You have more total points than 94% of all students."

Treehouse Badge(s) Earned Today:



Treehouse Courses Completed:
How to Make a Website
HTML
CSS Foundations
CSS Layout Techniques
Aesthetic Foundations
Design Foundations
Adobe Photoshop Foundations
Adobe Illustrator Foundations (66% complete, switched focus from web design to web dev)
Git Basics
Introduction to Programming
Javascript Basics

Codecademy (& other) Courses Completed:
HTML and CSS (Codecademy) 

Books Read or in Progress:

Completed: "Head First HTML and CSS," by E. Robson & E. Freeman
In Progress: "Eloquent JavaScript," by Marijn Haverbeke (On pg 27)
In Progress: "Head First Javascript," by Eric Freeman and Elisabeth Robson (On pg 56)
In Progress: "A Smarter Way to Learn Javascript," by Mark Myers (on pg 139)

My Progress on The Odin Project:
1.  Introduction to Web Development             100% Complete
2.  Web Development 101                                29% Complete
3.  Ruby Programming                                       0% Complete
4.  Ruby on Rails                                               0% Complete
5.  HTML5 and CSS3                                           0% Complete
6.  Javascript and JQuery                                  0% Complete
7.  Getting Hired as a Web Developer                 0% Complete

Hours Spent Coding Today: 2
Total Hours Coding: 571

No comments:

Post a Comment