Monday, July 27, 2015

Day 125: General Assembly Web Dev Meetup

I joined The Odin Project study group on Facebook, and also, CodeBuddies.com, which is a site used for taking part in Google Hangouts for studying purposes. 

I went to a web development meetup today at the public library on Cesar Chavez, in downtown Austin, hosted by General Assembly.  I thought it would be a great opportunity to learn about General Assembly.  The class was hosted by Elias Carlston, a web developer who started out as a coding hobbyist.  He emphasized the importance of notation in code, and the similarities between learning a foreign language and learning to code.

He defined a bug as code that produces an undesired output.  Sometimes a bug can be redefined as a feature, haha, if you change your mind about the usefulness of the output.  Web development is a niche of programming.  Some programming, for example, in certain car parts, is not web development, as there may not be a connection to the internet.  He mentioned DRY, "don't repeat yourself."  He mentioned that it is usually not ideal to reinvent the wheel, so we should adopt code from a library, if possible.

Computer scientists are not necessarily web developers, and web developers deal more strongly with monetizing the product and with user experience, for example.  He discussed Twitter's fail-whale, and how letting users know how many followers they had in real time was taking up a large amount of computing power.

There's a quote:

"It's going to be hard whether you learn fundamentals or not...might as well be a superstar."

Dennis Rodman was told he good overall, but was great at defense.  So, he focused intensely on defense, and became great.  

We should learn the fundamentals so as to build a solid foundation on which to grow on.  There's usually a complicated way to do things, and a shortcut way to do things, for example, via the use of a library.  We should learn the complicated way to it, so that we understand why the shortcut way works, but we should use the shortcut way.

General principles:

1.  Security
2.  Stability
3.  Scalability

The speaker also spoke of premature optimization, which deals with not optimizing code if you don't have to, basically in order to ship a feasible product within a desired time frame.  We can then optimize once it needs to be done and we have more resources with which to do so.

You have to enjoy solving problems, coding, and the logical/mathematical beauty of the code, in order to be willing to put in the time required.  The distinction between front end and back end only began to be really discussed in about 2008.  However, there isn't a hard line between the two.  Elias stated he's never had a project where he didn't have to at least do a little bit of back end work (Elias is a front end specialist).  

HTML, CSS, and JavaScript are the most common files.  An analogy could be made with the human body, with HTML as the skeleton, CSS as the skin, and JS as the muscles.  If a browser doesn't understand an HTML tag, for example a geo-location tag run on an older browser will simply be ignored.  This makes HTML very flexible, because support for new tags can be added to newer browsers, without crashing older browsers, as the new tags will simply be ignored by the older bowsers.

He spoke of single page apps, noting gmail as an example, which is in JavaScript.  He said these apps are becoming more and more popular, because the page doesn't need to be reloaded to access various functions of the app.  JavaScript is able to make these pages, and so front end developers are becoming JavaScript developers.

JQuery can be used to minimize problems caused by developers having to create different versions of their code for each browser.  JQuery is becoming less necessary as browsers are standardizing.

Elias then moved over to talking about the server side.  We went over DNS (domain name system), which converts your domain name into an IP address.  MySQL is open source database software, it's free, can be scaled up, and it's very popular.  Oracle is database software which is used by banks and other high requirement users.

Java tends to be a more complicated back end programming language, which tends to correlate with high paying, professional, big company jobs.  He mentioned that Ruby is an elegant language that's very user-friendly. 

The instructor used starting your car as an analogy to using an API.  We turn the key, and the car starts.  We don't see the inner workings of how the car actually starts, as the pieces interact, we simply insert the key and twist, and our wrist motion then starts the car, almost as if by magic.

Apache and NGiNX (pronounced Engine X) are server software technologies.  GUI is the Graphical User Interface, and it is pronounced gooey.  

The # 1 skill for a web developer is desire.  If you love coding, you will put in the effort required and be a great coder.  Vietnam has been educating children in programming for about ten years, and many of their graduates are very, very competent.  To work as a junior web developer, it can take you about 90 days, if you go at your training full time.  Elias mentioned that the jobs are out there, if you put in the work.

If you want to do remote work, other than git/github, is there any web dev language that might give you an edge in securing a remote position?  With remote work, your people skills matter a lot, more than any particular language, because you have to work as a team/coordinate, while dealing with time differences and distance.

O.k., now let's get back to Chapter 51...

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 155)

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: 579

Saturday, July 25, 2015

Day 124: Chapter 47 of the JavaScript Book

The next chapter is Chapter 47 Events: Mouse.  This is how to make an image change into another image when the user scrolls their mouse over it:
<img src="theimagefile.jpg" onMouseover="src='thesecondimage.jpg'">

Notice the single quotes inside of the double quotes.  You can also use onMouseOver with other html elements:

<h1 onMouseOver="alert('Be sure to get your shopping done today.');">World Ends Tomorrow</h1>

In the example above, you could instead call a function that makes the alert appear.  Here's the JavaScript alternative to the preferred CSS color-change hover:

<a href="index.html" onMouseover="this.style.color='green';">Home Page</a>

When the user goes over the link, it turns green.  This makes the paragraph expand when the user hovers over it:

<p id="loris" onMouseover="expand();">Slow Loris: Mouse over for more info</p>


In the examples above, when the user mouses away from the image, nothing happens, but normally you would want the image to go back to the initial image, so you would use the onMouseout event handler:

<img src="before-pic.jpg" onMouseover="src='after-pic.jpg'" onMouseout="src='before-pic.jpg'">  

All right,I finished that chapter.

This code puts an image on the page, which then switches to another image when you mouse over it and then back to the first image when you mouse out of it:

<img src="janice-before.jpg" onMouseover="src='janice-after.jpg'" onMouseout="src='janice-before.jpg'">

Now I'm on Chapter 48 Events: Fields.  I worked on code like this:

<input type="text" onFocus="this.style.backgroundColor = 'yellow';">

We really aren't supposed to be styling with JavaScript, as CSS can do this, but it's a part of the book, and the author felt we should know that JavaScript has this capability, even though it's not encouraged that we use it.  

The next chapter is Chapter 49 Reading Field Values.  Here's the first code we used:

<form>
    Email:
    <input type="text">
    <input type="submit" value="Submit">
  </form>


That creates an input field and a submit button, except the input type is not "button," it is "submit."  We worked on this code:

What is your name?<br>
<form onSubmit="sayHi()">
  <input type="text" id="name">
  <input type="submit" value="Submit">
</form>

<script>
function sayHi() {
  var userName = document.getElementById("name").value;
  alert("Hello, " + userName + "!");
  window.close("mywindow");
}
</script>


It's cool, it makes a popup/alert that says "Hello," followed by the name that was entered into the text.  We worked on this code as well:

Enter dog or cat:<br>
<form onSubmit="checkPet();">
  <input type="text" id="whichPet">
  <input type="submit" value="Submit">
</form>

<script>
function checkPet() {
  if (document.getElementById("whichPet").value === "dog") {
    alert("Bow-wow!");
  } 
  else {
    alert("Meow!");
  }
  window.close("mywindow");
}
</script>


It's neat.  The next chapter is Chapter 50 Setting Field Values.  In this chapter, I was reminded that the value to the right is assigned to the item on the left, even if the item on the left is a function and the item on the right is the variable (although a function is technically a variable).  For example:

document.getElementById("city").value = cityName;

The code above would assign cityName to item on the left.  So, in that manner, we are "writing" a value into a field, without the user typing it in.  This can be used, for example, if a user enters a zip code in a previous field, and you want to retrieve the appropriate city and place it into the city field automatically, saving the user some time in filling out the forms on the page.

I completed chapter 50, so the next chapter is Chapter 51 Reading and Setting Paragraph Text.  I went back to the Odin Project and dropped in on Codecademy's JQuery track, which is what I was planning on doing next after completing the book.  I'm just curious as to what's coming up, my plan still remains to complete the JavaScript book, because it's been the best JavaScript teaching tool I've encountered thus far.  The curriculum call for doing only the first three sections of that track at this time, those being "Introducing JQuery," "JQuery Functions," and "Dynamic HTML."  After that, I'm supposed to 

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 155)

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: 3
Total Hours Coding: 577

Thursday, July 23, 2015

Day 123: Chapter 45 of the JavaScript Book

I began today with Chapter45 of the JavaScript book, Events: Link.  This is really neat:

<a href="#" onClick="alert('Hi');">Click</a>

So, within the html, right before the closing body tag (</body>), if the code above is inserted, when it is clicked, an alert will appear.  This is different from the usual html use for the <a href="http://www.genericsite.com">Click</a> tags, which would actually take the user to the web address in the tags if the "Click" text is clicked.  

As a side note, alert() calls a function that pops up an alert.  It's not a function that I created or stored anywhere, it's just a function that must be stored in the browser, since JavaScript is retrieving it from somewhere, even when you're offline.  It's neat because as I've been learning about functions, I think of where they're stored so that I can call them, and then I noticed that alert() is itself a function.

The # inside those html tags tells the browser to reload the current page.  Note that the quotes inside the double quotes are single quotes.  In JavaScript, you aren't allowed to nest double quotes inside double quotes or single quotes inside single quotes.  I imagine that' because then double quotes inside double quotes looks like two sets of quotes, one after the other, instead of one set of quotes with another set inside of it.  The same applies for single quotes inside of single quotes, again, they are also not allowed.

One problem with the code above, which works, is that when the user clicks the link, after the code runs, the page will scroll all the way to the top, which we don't necessarily want to do.  To avoid that, use this code:

<a href="JavaScript:void(0)" onClick="alert('Hi');">Click</a> 

The code above only executes a single JavaScript statement, but there is no limit to the number of JavaScript statements that you can enclose in the quotation marks.  Note also that there is no semicolon after the parentheses after void.  If you use multiple statements of code, all should be in the same set of quotes, separated by semicolons, like so:

onClick="var greet='hi'; alert(greet);"

Notice how alert is not in its own set of quotes, the alert and the var are both within the same set of quotes.

Next was Chapter 46 Events: Button.  We learned to use this code:

<input type="button" value="click" onClick="alert('Hello World!');">

You can also do this with images, like so:

<img src="image.jpg" onClick="alert('Please do not click on the glass, haha.');">

The next chapter is Chapter 47 Events: Mouse.

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 155)

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: 576

Wednesday, July 22, 2015

Day 122: Chapter 41 of the JavaScript Book

I began today with Chapter 41 of the JavaScript book.  Chapter 14 goes over while loops.  Here's an example:

var i = 1;
while (i < 6) {
  alert("We're on iteration " + i + "!")
  i++;


The code above makes an alert appear on the screen which shows which iteration the loop is on.  The loop makes 5 iterations, and then stops.

Next was Chapter 42 Do...while loops.  Do...while loops are very similar to while loops, but they have a different format, like so:

var i = 0;
do {
  alert(i);
  i++;
} while (i < 0) ;

Because the while statement is at the end of the Do...while loop, the loop will always run at least once, unlike the while loop, which would not run even once using the conditions above, because i is not less than 0 to begin with.  

All right, I finished that chapter and moved on to Chapter 43 Placing Scripts.  It kind of seems like I'm finally getting to the good stuff.  I've been learning a lot of JavaScript code, but it's all just logic and math, which is a fun game, but I haven't yet seen JavaScript code actually applied to a website to do anything really useful.  I've seen code that is supposed to do neat little games, like the 99 bottles of beer on the wall game I coded, but that's about it.  I'm looking forward to applying my JavaScript knowledge to make some fun things with some kind of utility that I can actually deploy.

So Chapter 43 dealt with placing scripts.  One is to link to an external JavaScript file, like so:

<script src="thefile.js"><script>

Another way is to insert the code in the actual html file, like so:

<body>
<script>
alert("hahaha");
</script>
</body>

The chapter says we should place both JavaScript inserted directly into the html and JavaScript inserted via a link to an external file, at the end of the body section (before the closing body tag).  This allows the body content, like images and such, to load before the browser attempts to load the JavaScript.

The next chapter was Chapter 44 Commenting, which dealt with how to comment in your code.  It was a quick read, // will comment out everything to the right of it on that specific line of the file, while /* and */ will comment out every line between the first and second forward slash. 

In html, we can comment by inserting our comments into this: 

<!-- comment here -->

In CSS, we can comment by using the /* and */.  JavaScript files tend to be more complicated than html or CSS, so we should leave very good comments, to aid others who may later work on our code and need to know why we did what we did and what does what.

All right, that's enough coding for the day.  I'm going to go study Tagalog for an hour or so.  I speak English and Spanish fluently, and I decided to learn Tagalog (the main language of Manila, the capital of the Philippines) as a fun activity to add to my life.  I started yesterday, and my plan is to get an hour of Tagalog in a day (I'm learning with Rosetta Stone).  I try to do two hours of coding a day, and sometimes I get more done, but if I do a minimum of two hours a day, it keeps my mind in coding mode, and I maintain my momentum.  Since this method is working really well since I adopted it about a week ago with coding, I thought I'd apply it to learning Tagalog as well. 

Tomorrow, I'll start with Chapter 45 Events: Link.

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 148)

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:3
Total Hours Coding: 574

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

Monday, July 20, 2015

Day 120: Reviewing Euler Problem Solution(s) and Uploading to Github

So, as noted yesterday, here was my solution to Euler Problem 3:

function maxP(a) {
var b = a - 1;
var IsPrime = true;
while (b !== 1) {
  if (a % b === 0)
    IsPrime = false;
    b = b - 1;
}
if (IsPrime === true) {
  console.log("Prime");
  console.log(a);
 }
}

function euler3(x) {
  for (i = x; i > 1; i--) {
    if (x % i === 0 && maxP(i) === true) {
    }
  }
}

var stringNumber = prompt("Give me a number, and I will give you the prime factors, starting with the largest!");
var parsedNumber = parseInt(stringNumber);
var x = parsedNumber;

euler3(x);


Then, here's a really neat solution by a user named Marina Drigo:

function findPrime(input){
    var prime = 0;
    var x = input;
    var div = 2;

    while (x > 1)
    {
        while (x % div === 0){
            prime = x;
            x = x / div;
        }

        div++;
    }
    return prime;
};

var input = 600851475143;
var result = findPrime(input);
console.log(result);


That code works amazingly well, and I want to understand why...

O.k., so, I started today with looking at my code for the problem and making it run in reverse compared to how I had it, which is to say, I made it run from 1 to the required number, instead of from the required number down to 1.  This had the effect of getting to the prime factors much faster (because the prime factors for a number are clustered closer to 0 than they are to the number itself).  I also capped the resulting prime factors at numbers below 10,000.  So the code will give all the prime factors of a number, as long as the prime factors are below 10,000.  Here's the improved code:

function maxP(a) {
var b = a - 1;
var IsPrime = true;
while (b !== 1) {
  if (a % b === 0)
    IsPrime = false;
    b = b - 1;
}
if (IsPrime === true) {
  console.log("Prime");
  console.log(a);
 }
}

function euler3(x) {
  for (i = 2; i <= 10000; i++) {
    if (x % i === 0 && maxP(i) === true) {
    }
  }
}

var stringNumber = prompt("Give me any number, and I will give you the prime factors of that number, from smallest to largest, as long as they are below 10,000!");
var parsedNumber = parseInt(stringNumber);
var x = parsedNumber;

euler3(x);


It works great!  It actually finishes the calculation very quickly, as long as you don't enter a number that has a prime factor greater than 10,000.  :)

O.k., so now I'm gathering up my Euler Problem answer for problems 1 through 3, polishing them up, and getting them ready to be uploaded to github...

So while working with the Command Line (for Github purposes) I came across the old issue I had with the Command Line not wanting to access a folder.  I inserted a _ instead of a space between the two words of the folder name, and that worked, I was able to access the folder.  This has happened before, and I need to get into the habit of naming all my folders with a _ instead of a space.

All right, I created the readme file and pulled it down to my local folder.  I then submitted my solutions to the Odin Project, and the pull request is pending approval.  Great day so far! 

At this point, I've got to choose whether co continue with the book and finish it or continue with the next part of the Odin Project.  So far, the book has been the best book on coding I've ever gone through, it has brought a lot of value to the table, thanks to it, I was able to finally solve Euler Problem 3.  So, I'm going to continue my progress on the book, which, at a rate of 4 or 5 chapters a day, should take me about 10 more days to complete. 

O.k., so after doing the work above and loading the work to Github (and submitting a pull request), I moved on to Chapter 39 Switch Statements: How to Start Them.


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 89)

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: 3
Total Hours Coding: 569

Sunday, July 19, 2015

Day 119: Euler Problem 3

Yesterday, I worked on functions and then went back to Euler Problem 3.  Today I'm back to working on solving that problem.  Solved Euler Problem 3!!!

function maxP(a) {
var b = a - 1;
var IsPrime = true;
while (b !== 1) {
  if (a % b === 0)
    IsPrime = false;
    b = b - 1;
}
if (IsPrime === true) {
  console.log("Prime");
  console.log(a);
 }
}

function euler3(x) {
  for (i = x; i > 1; i--) {
    if (x % i === 0 && maxP(i) === true) {
    }
  }
}

var stringNumber = prompt("Give me a number, and I will give you the prime factors, starting with the largest!");
var parsedNumber = parseInt(stringNumber);
var x = parsedNumber;

euler3(x);


The code above makes a prompt, you enter the number, and then it returns the prime factors, starting with the highest.  The problem is that it takes a LONG time to do so, but it works.  I looked at three other student solutions, two did not work properly, but the third works fantastic, so I'm posting it here, it's by a user named Marina Drigo:

function findPrime(input){
    var prime = 0;
    var x = input;
    var div = 2;

    while (x > 1)
    {
        while (x % div === 0){
            prime = x;
            x = x / div;
        }

        div++;
    }
    return prime;
};

var input = 600851475143;
var result = findPrime(input);
console.log(result);


I'm going to spend tomorrow studying this solution to understand it's simplicity.
 
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 89)

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: 566

Saturday, July 18, 2015

Day 118: Chapter 36 of the JavaScript Book

I finished Chapter 35 Functions in the last session, but I started off this session with a quick review of that chapter.  Next I went on to Chapter 36 Functions Passing Them Data.  I finished that chapter and went on to Chapter 37 Functions Passing Data Back From Them.  The difference between an argument and a parameter was a bit confusing, but it seems the argument is the data that is placed inside the parameter.

I coded up this function, with a return keyword at the end (and called it with merch(50) in the example below):

function merch(merchTot) {
  var orderTot;
  if (merchTot >= 100) {
    orderTot = merchTot;
  }
  else if (merchTot < 50.01) {
    orderTot = merchTot + 5;
  }
  else {
    orderTot = merchTot + 5 + (.03 * (merchTot - 50)); 
  }
  return orderTot;
}

merch(50);


I like functions.  Note that a function may only return a single value to the code that calls it.  Also, a function may be used within a function call:

var orderTot = merchTot + calcTax(merchTot);

And also can be called within another function:

function calcTot(price) {
  return price + calcShip(price);
}

Neat.  Next I moved on to Chapter 38 Local VS. Global Variables.  A variable has local scope when declared within a function, that is, when you use var to declare it within the function.  Important to note is that if you get sloppy and use a variable within the body of a function without explicitly declaring it, it will be global.  This is not good practice because it will cause confusion.  Also, variables that are named as parameters are implicitly local variables.

Let's say you declare the same variable inside and outside a function.  Then in that case, that variable will have different values within and without the function.  This is not good practice, and in this case, within the function, the global variable is said to be in the shadow of the local variable.

Although a function can use global variables, this is not good practice.  It is always best to pass values explicitly to functions through arguments (passed through parameters).  Also, you can change the value of a global variable within a function, and this will happen whether you use return or not, but it's better practice to use a local variable within the function, then pass that value back explicitly through a return statement.

The next chapter is Chapter 39 Switch Statements How to Start Them, but I wanted to give Euler Problem 3 a shot again now that I've brushed up on functions. So I worked on that for an hour or so...still working on it.

I learned that x /= y means x = x/y.  Here's a bunch of operators on the left and the translation on the right:

x++ x=x+1
x-- x=x-1
x+=y x=x+y
x-=y x=x-y
x*=y x=x*y
x/=y x=x/y

Neat.
 
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 89)

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:4
Total Hours Coding: 564