Monthly Archives: November 2014

Learning JS Properly

I’m sure you have all come across the  blog JavaScript is Sexy, well the How to  Lean JavaScript Properly tutorial has been updated! 🙂 But , it seems I missed the boat on the study group! 🙁 They are already in week 5. Hopefully there is another  study group starting up on reddit or elsewhere, that I can join virtually. If anybody knows of one please let me know!!

Anyway, I figured I would continue on my own and document my progress here, while making study notes.

While covering Increment and Decrement Operators, in Chapter 2  of the book Beginning JavaScript (4th edition), I noticed  the way they covered this topic was rather unique. They stress that placement of your increment/decrement operators matters. I never gave it too much thought in the past, as I’ve pretty much only used basic pre and postincremnts/decrements in my for/while loops. But I’m now stopping to seriously think about the affect these operators will have on my future code.

Consider the following code for example:
someNumber = 25;
someVaraible = someNumber++ - 10

This code subtracts 10 from someNumber and then someNumber is increased by one. That’s easy the answer would be 16. No big deal right? But if you were to say have something a bit more involved like this:

someNumber= 4;
someVariable = SomeNumber++ * 2 + 1; //this equals 10
4 * 2 = 8 + 1 = 9 + 1 (the postincrement++) = 10. Here the number is increase AFTER the calculation.

or if you do
someNumber = 4;
someVariable = ++SomeNumber * 2 + 1; //this equals 11
4 + 1(the ++preincrement) = 5 * 2 = 10 + 1 = 11 Here the number is increased BEFORE the calculation begins.

As you can see the placement matters. It affects the entire computation of the code! Now, as someone who is has not wrote vast amounts of code it is very easy to make a mistake, which would cause errors in my code. So I’m glad I’m they pointed this out with example code. I recreated my own example here so that I can have a more solid understanding before moving on. Hopefully this helps you too!

Methods and Arrays in Java

Wow, I’m more than halfway through the semester. We just finished learning how to create methods in Java and now we are focusing on arrays. It amazes me how similar, yet different programming languages are. In Java arrays must be of the same data type where as in JavaScript arrays can be declared like almost any other variable and can contain an array of variable types. No pun intended ha!

Last week, we worked on a program that checks whether a number is palindrome. I used two methods in this program. This assignment  was actually pretty cool. It asks the  user to input a multi-digit number. If the number entered is less than 0 or  is less than 10, the program rejects that number, and asks the user to enter another number. I used a while loop for that! 🙂

When the user  finally enters a mufti-digit  number the number is then reversed with a reverse method.  Finally the ispalindrome method checks to see if the number reversed is equivalent to the  the number initially entered.

I would  share my code with you, but I’m sure that would be frowned upon by my school and my professor.  But I can at least talk about it, which is cool! 🙂

On a positive note I’m getting faster at creating my programs. It used to take me a few days to write a program, but now I can finish one in a few hours! You have no idea how confident and happy that makes me feel! I’m slowly but surely becoming a stronger programmer!!  🙂