Friday, January 10, 2014

Badge Happy

     Stupid! That's what it is! When a lesson has a specific way that it wants you to do a line of code, and then DOESN'T tell you!
Let me show you:
var x =
var y =

//The ternary operator in action
result = x > y ? "good job" : 20;

//Rewrite the ternary code using if else statements
First I tried to use return, but that gave me some error messages, but then I tried this and it worked, but I didn't pass the lesson:
if (x>y){
   console.log("good job");
}else{
   console.log(20);
}
See the 'result' in the ternary operator? Turns out you need that instead of anything else, because; they feel like it. 
That's stupid. I understand using result, but they could have told me that....
I finished the conditionals section! Olé!







And Now I'm doing a dice game and using math. 
var die1 = Math.floor(Math.random()*6 + 1);
Math.Whoever created the math section in .js is hilarious! 
Today's post is brought to us by a nice latté and some Electric Light Orchestra. Time to plug in atd plug away!
I just got ridiculously happy, because; I finished a lesson with no errors and passed at the very first try! WHOO!!
 One of the really cool things that I like about having a forum, is that I can see how other people wrote their answers, and how they are different from mine. 
For instance, this is mine:
 // here we need to check if there are doubles.  If so, score should be
  // double the sum of the two dice
  if(die1+die2%2===0){
    score=(2*(die1+die2));  
  }else{
      score=(die1+die2);
  }
}
and this is someone else's:
// here we need to check if there are doubles. If so, score should be
// double the sum of the two dice
if(die1===die2){
score=(die1+die2)*2;
}
else{
score=die1+die2;
}
}

Personally speaking, I like what they did with the <if (die1===die2)> better than my <if (die1+die2%2===0)> their's is so much more simple! I should have thought of that...
Simplicity is what I'm trying to go for every time I write code. So, I'm now upset that I didn't do a better job at it. Oh well, next time I'll know.
Hopefully, they won't split each test into something like this: // Define a function named calculateTotalCosts 
// declare a variable fixedCosts the value of 5000
// have the function return fixedCosts

I can do that easily. why not have the text three things in the same page?
Ah well. See y'all Monday! 
--Martin 

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

Monday, January 6, 2014

Staying Frosty!

        So, the weather decided to be redonkulous today. In Texas, 33 degrees Fahrenheit is crazy cold even when there's no wind, but I got out of the house and game to my coffee shop to get my coffee on and some code done!
 I thought I'd start with some links that I found and/or were shared with me on G+:
link one:
http://www.christopherbiscardi.com/2014/01/06/flattening-nested-arrays-in-javascript/
I'm not COMPLETELY sure how this will be applied to me, but I've got some stuff that I'm working on that I think could be aided by this.
Also this:
http://www.javaworld.com/article/2078724/mobile-java/10-steps-to-becoming-the-developer-everyone-wants.html
The bullet points were enough for me, but read the definitions if you're crazy like that.

So, now down to business. I'm playing a Chris Cornell album called Carry On. I love the songs on here. A few covers, but they're decent.
Today's lesson starts off with MOAR conditionals.
var legalDrivingAge = 18;
var canIDrive =
  // write if else statement here. Return true or false
Have to make it return true or false if they can drive. This'll be easy. The next one will probably be crazy insane. That's how they do it. 
Turns out this was the crazy insane one. T`hose tricky bastards.
Also, what the hell does 
"Expected an identifier and instead saw ';'
missing semi colon."
Mean?? That's contradictory!
Side note:
doing my studies at a coffee shop is interesting in that I will occasionally glance around whilst sipping my latté (could actually afford one today! XD) and I'll be like; woah. those people weren't here a second ago. wait, it's been an hour?? haha!! 
// Define the function under this line
var canIdrive=function(myAge,legalDrivingAge){
 if(myAge>=legalDrivingAge){
     return true;
 }else{
     return false;
 }
};

// Declare legalDrivingAge under myAge
var myAge = prompt("How old are you?");
var legalDrivingAge=18;

//Create an if else statement using the function as a condition
if (myAge>=legalDrivingAge===true) {
  console.log("You can legally drive!");
}else {
  console.log("You'll have to wait a few more years!");
}
see that first 'var'?
yeah it just took me twenty minutes and a few WTFs to figure out that I missed that in my code...
Yup. Every coder person does that. well that was forever! 
see y'all wednesday!
--Martin

Friday, January 3, 2014

Plug In And Plug Away

    Conditionals!
Apparently I need to brush up on my terminology, because; I've been using these for a while, but I didn't know their name. Oops.
Once again, I'm at my favorite coffee shop trying to get some classwork done. I'm a little early because my boss said no work today. So, I headed over here after a decent sleep. Now to get an hour or to in. I try not to work for too long. I start going crazy. So, a walk or something will probably happen in the middle of this.
I finished the taxiFare section and am now in an overview of everything I've done up to this point. Mainly they just want me to check out their blog. So, I'm going to plug in my headphones, get some of Them Crooked Vultures going, drink my iced tea because I'm too broke to buy coffee, plug in and plug away!
Coding notes:
Seriously, <else if> rocks, but I know how it works. I think that they think I wasn't paying attention to anything they said.
I've been waiting for <&&> to make a show. And now, TADA! <&&> everywhere!

var checkNameGender = function (yourName,gender) {
//All the code below was used in exercise 1.6

    if (gender.length > 0 && yourName.length > 0) {
      if (gender === 'male' || gender === 'female') {
            return true;
      } else {
            return false;
      }
    } else {
      return false;
    }
};
checkNameGender("Mookie","male");

And there's my last lesson. I actually went through that really easily. Finish on success, right?
I've always liked the idea of having Mookie for a nickname. Now I can amuse  myself by telling the code to call me Mookie. =-)

Thursday, January 2, 2014

First!

January 2, 2014.
      I've been trying to learn to code for a while now, and I haven't made as much headway as I would like; so I'm going to use this blog as a narcissistic way to keep myself on track. I'm trying to learn .js and get some knowledge under my belt. I am an absolute n00b. I'm just now getting comfortable with variables and functions. Right now I'm using code academy, Udacity and random stack overflow places that answer my urgent Google searches. My current hardware is a Chromebook Pixel. Boom. Yup, on a Pixel. All my classes are online so, right now I don't need any hardware-specific. When I need something like BlueJay (or whatever it's called) I'll just use Crouton! Linux FTW! 
I'm going to start with a M-W-F schedule and we'll see where it goes from there. Expect screenshots, strange comics, and anecdotes with a hint of Southern in there. 
A little about my person.
I am twenty four, I live with my parents in the boondocks of Texas. Or, as the Australians would put it, waaay past the black stump! I work in general construction right now, but obviously want a better job. I'm aiming at front-end web development and once I have that down(ish) I want to go forward with android app development. hopefully by this time next year, I'll be in a better place.
So, to start, I'm going to go jam some Pink Floyd and get some class work done.
Here's what I worked on today:
// add a parameter called hourOfDay to the function
var taxiFare = function (milesTraveled,hourOfDay) {
  var baseFare = 2.50;
  var costPerMile = 2.00;
  var nightSurcharge = 0.50; // 8pm to 6am, every night
  var cost = baseFare + (costPerMile * milesTraveled);
 
  // add the nightSurcharge to the cost starting at
  // 8pm (20) or if it is before 6am (6)
 if (hourOfDay>=20||hourOfDay<6)
 {
     return nightSurcharge+ baseFare + (costPerMile * milesTraveled);
 }else{

  return cost;
}
};
console.log(taxiFare(12,13));
It's not exactly elegant, but I got it to work!
the idea was to get taxiFare to print out the bill and have the option to put in time of day. That if(hourOfDay) bit had we stuck for a while! But, I'm through it. =-)
--Martin