Tuesday, October 27, 2015

Day 153: FCC, Intermediate Algorithm Scripting

Okay, today I'm starting up with problem 14 of Intermediate Algorithm Scripting.  Here's a function that tells me if a number is a prime number or not, it returns true if it is, and false if it's not:

function prime(a) {
  var b = a - 1;
  var isPrime = true;
  while (b !== 1) {
    if (a % b === 0) {
 isPrime = false;
}
b = b - 1;
  }
  if (isPrime === true) {
    return true;
  }
  else {
    return false;
  }
}

So now I've got to make a loop that runs the number given, and every number below that, though the formula above, and then adds all the numbers that result in true.  I've got a plan, and that's how all these things start.

Side note, this iterates through an array to find the max value:
var maxValue = null;
for (var i = 0; i < myArray.length; i++) {
  if (maxValue === null || maxValue < myArray[i]) {
    maxValue = myArray[i];
  }
}

That code may be useful later.

I solved it!

 function prime(a) {
  var b = a - 1;
  var isPrime = true;
  while (b !== 1) {
    if (a % b === 0) {
    isPrime = false;
  }
  b = b - 1;
  }
  if (isPrime === true) {
    return true;
  }
  else {
    return false;
  }
}

function sumPrimes(num) {
  var arrayOfPrimes = [];
  for (var j = 2; j <= num; j++) {
    if(prime(j) === true) {
      arrayOfPrimes.push(j);
    } 
  }
  var primesTotalled = 0;
  for (var k = 0; k < arrayOfPrimes.length; k++) {
    primesTotalled = primesTotalled + arrayOfPrimes[k];
  }
  return primesTotalled;
}


sumPrimes(10);

I feel great, it looks like the problem I was having was that I was over complicating things, it was more simple than I thought.

On a side note, FCC added a section, which is now section 11 (the other sections moved up a number), titled "JSON API's and Ajax," so I've made that adjustment below.  It also added some new content to section 6, "Basic JavaScript," so I went back to that section and completed the additions, which were fairly minor.

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 (768 pgs.)
In Progress: "Head First JavaScript," by Eric Freeman and Elisabeth Robson (on pg. 56)
Completed: "A Smarter Way to Learn JavaScript," by Mark Myers (293 pgs., 89 chapters with 20 questions/problems per chapter, for a total of 1,780 coding questions/problems answered)

My Progress on The Odin Project:
1.  Introduction to Web Development                                             100% Complete
2.  Web Development 101                                                               33% Complete 
Note: Switched to FCC for the great online community and better updates/support.

My Progress on Free Code Camp (FCC): 
1. Get Started with Free Code Camp                                                      Complete
2. HTML5 and CSS                                                                                 Complete
3. Responsive Design with Bootstrap                                                       Complete
4. Gear up for Success                                                                           Complete
5. jQuery                                                                                              Complete
6. Basic JavaScript                                                                                 Complete
7. Object Oriented and Functional Programming                                     Complete
8. Basic Algorithm Scripting                                                                   Complete
9. Basic Front End Development Projects                                                 On 4 of 5
10. Intermediate Algorithm Scripting                 On 4 of 21 (#13 and #14 also done)

11. JSON API's and Ajax
12. 
Intermediate Front End Development Projects
13. Claim Your Front End Development Certificate
14. Upper Intermediate Algorithm Scripting
15. Automated Testing and Debugging
16. Advanced Algorithm Scripting
17. AngularJS
18. Git
19. Node.js and Express.js
20. MongoDB
21. Full Stack JavaScript Projects

22. Claim Your Full Stack Development Certificate

After the FCC work above (estimated to take 800 hours), there are 800 more hours of coding projects on behalf of non-profits, which, in addition to contributing to the common good, provide us an opportunity to expand our networks and build a robust portfolio.


Hours Spent Coding Today: 5
Total Hours Coding: 712

No comments:

Post a Comment