Wednesday, January 8, 2014

What The What!

     Ever since the beginning of this course, I've been working with if/else statements and conditionals. It would seem that thing are about to take the next step. Now I'm starting on switch statements. OlĂ©? I'm actually pretty happy with my rate of studying. I just have to keep on plugging in and plugging away. Ok, so I'm working away with the switch statements(Which are awesome BTW) and now they're saying there's another way to do it called Ternary operators. According to el Goog, 'ternary' is an adjective meaning composed of three parts, or in mathematics, means using three as a base. Now to find out if that is what it means in programming. They say they are an ugly name. That's kind of dumb. I like the sound of the name. Ternary. Sounds like it's about a bird or something. But I digress, back to the code shtuff. The Offspring is my soundtrack today. I'd never heard of them, but my friend suggested them, and I am really liking them. My drink is some black coffee. Don't want to have the same type of thing all the time, right?
What the what! I know <if/else> stuff; now ternary operators can do that in one line?
Why did I learn <if/else> ? It better be because sometimes it's better to use one over the other.
Here's what I mean:
var x = 7;
var y = 4;

if (x > y) {
  result = "good job";
}
else {
  result = 20;
}

//Below is the above code written using the ternary operator
result = x > y ? "good job" : 20;

See what I mean? 
If I find out there's something after this that's even simpler, I'm going to be upset with these dudes.
Fist pump! I'm getting these down easy!
Maybe that's why they started with <if/else>? I hope that they had a plan when they did this.
So, the good news is that I can read the code they have set up for me and see what it means, the bad news is that now when I read anything and see punctuation commonly used in .js (<>?/+===) for instance, I start reading in 'code mode' when it's not code, and I get confused for a sec. That will probably go away after a bit. I hope?
That's all for me folks. I got a lot done today! See Y'all friday!
--Martin