Showing posts with label simplicity. Show all posts
Showing posts with label simplicity. Show all posts

Wednesday, March 5, 2014

Chippy Animation/New Method For You In There.

     Rejoice! There is HTML/CSS today! Olé!  I am here at the house up at way too early an hour for my liking, but I'm up and done with the necessities of the day, so let's get this going. You'll be happy to know that I'm listening to something else besides GrooveShark. I found some free ChipTunes albums thanks to MakeUseOf. They proved themselves worthy of my followingness. Followingness is now a word by the way. I didn't have any coffee today. Yet. So, if you see any grammar errors, blame it on that. I'll probably get a water later. 

     

HTML/CSS

     Animations! That's what we're working on today. It's a simple animation, really. We're just going to do model of the solar system. Sadly, there doesn't seem to be a cool scientific name that goes with that. Anyhoo, to start out with, it's just the sun and earth. I'll see if I can get more in there afterwards.

     The first new thing is this:

#earth {
     /* Style your earth */
     position: absolute;
     top: 25%;
     left: 25%;
 }

The %'s make the image in the earth tag adhere to a grid. It's much easier to use the % when you just need something in a general area. You can still use the <px> method if you need more accuracy.
The next new thing is:

box-shadow: 0 0 64px 10px white;

That's a line of CSS. Box-shadow does pretty much what you would expect. It gives a shadow to any element that you want. Here's what Mozilla tells us about the box-shadow's parameters:

"1st <length>
Specifies the horizontal offset of the shadow. A positive value draws a shadow that is offset to the right of the box, a negative length to the left.
2nd <length>
Specifies the vertical offset of the shadow. A positive value offsets the shadow down, a negative one up.
3rd <length>
Specifies the blur radius. Negative values are not allowed. If the blur value is zero, the shadow’s edge is sharp. Otherwise, the larger the value, the more the shadow’s edge is blurred.
4th <length>
Specifies the spread distance. Positive values cause the shadow to expand in all directions by the specified radius. Negative values cause the shadow to contract."
The 4<length> also is the part that deals with brightness.

     You know things are about to get fun when the lesson starts off with this:

"The next couple of steps are going to be a little tricky, so hang in there."

Let's see what they're about to throw at us.

     
     The first thing we had to do was to surround the <img> tag with a div with the id "earth-orbit" I guess that means we're about to get some movement here! I was right! We have movement! Earth is spinning away because of webkit stuff. I won't really get into that right now, but it's pretty much what moves things around. To see the finished code/product plus a few planets, go here.  I'm pretty sure that they're going the wrong way, and I know that the scale for size and distance is off. I just did it for fun. 

JavaScript


Today, we get to deal with a new method called <hasOwnProperty> it gives back a boolean response as to what is in an element. Search for what you think is there, and it'll tell you. Example:

var myObj = {
    // finish myObj
    name:"john"
};

console.log( myObj.hasOwnProperty('name') ); // should print true
console.log( myObj.hasOwnProperty('nickname') ); // should print false

This might seem stupid now, but when you're dealing with thousands of lines of code, where the object is more complex, or it's not easy to be sure, this is what you want. It'll tell you straight up!

And here we have a use-case in an <if/else> statement:

var suitcase = {
    shirt: "Hawaiian"
};

if(suitcase.hasOwnProperty("shorts")){
    console.log("You remembered to pack!");
}else{
    suitcase.shorts="blue";
    console.log(suitcase.shorts);
}

So, as you can see, it's got quite a lot of good uses!
I've already gone over the <for> loop and I might have talked about the <for-in> loop? Not sure. Let me recapitulate: the <for-in> loop is like the <for> loop, but it's more simple. Here's a comparison:

The <for> loop that would print out the contents of an array:

var array = ["hey", 2, true,"dude"];

for (var i = 0; i<array.length; i++){
             console.log(array[i]);
}

It's cycling through each element of the array, and printing it out to the console.

And here's a <for-in> loop doing the same thing:

var array = ["hey", 2, true,"dude"];

for (var i in array){
             console.log(array[i]);
}
notice how less verbose it is.

Now, you might be thinking that having these two loops that are practically the same is just stupid. Why not just have one? Actually, if you look at the first loop, you'll notice that it has a specific end-point. It's only going to go as far as the end of the array, and when you're using it to do something else that needs a specific end-point, like creating a long list of numbers that doesn't crash, that would be the <for> loop. The <for-in> loop works better for these types of use-cases. Something where you're worried about the properties in an element and you need them printed out, numbered, or anything else you can think of.



     That'll about do for me today, folks! I had a lot of fun with this one! There was a lot of new stuff going on. I like new stuff. See y'all on Friday!

--Martin

Monday, January 20, 2014

New Font New Lessons

     Well, I'm at the coffee shop. I wasn't planning on going here, but the internet is down. I mean really down! the line got cut somewhere between our neighbor's house and our house. So, the company is going to be digging around fixing all of that for a while. So, here I am getting stuff done and having a good latté. I got a little sidetracked by some questions about my Chromebook Pixel, and it does cut quite the figure, so I can understand people asking about it. I'm back on track now. The music for today is: The Crystal Method. I'm not really sure how I came across it, but I put in my Google Play Music a bit ago, and voilà! Cool music! I'll probably throw some Pink Floyd in there too. The radios are just playing their two most popular songs according to them: Another Brick In The Wall, and Wish You Were Here. It makes me want to hear more than just those two, but enough chatter! Time to plug in and plug away!

     Today, the lessons are starting out with arrays. From some Googling and just general info received from people, I know that arrays are going to be very useful. So, I need to keep my head up.

     Yay! Loops and arrays! Check it out:
// Let's print out every element of an array using a for loop

var cities = ["Colorado", "The Grand Canyon", "A lot of Europe", "NYC because Gotta go at least once, I suppose.", "Japan", "Damn Yankee States", "New Orleans"];

for (var i = 0; i < cities.length; i++) {
    console.log("I would like to visit " + cities[i]);
}

It kind of had me there for a bit until I realized they weren't trying to print numbers, they were printing the elements in the array and calling them in order by number.
I added in the elements in the array. As you can see, I want to visit a profuse amount of places. Of course, this isn't an exhaustive list.
     Wow. These people don't even remember what they are saying! They said, and I quote: "Remember, arrays use zero-based indexing!" The Image they show with it? <var arrayName=[1, 2, 3];> Um... no! That is NOT zero-based indexing! This is: <var arrayName = [0, 1, 2];> Duh. It's not like they don't know this! I learned what zero-based indexing is from them; they just can't show their work correctly all the time. Also, it would seem I should have known that if I have a <for> loop, you just run it. You don't need to print it to the console. I noticed that it was printing out the array in order going down, and then having it inside the brackets with the quotes and everything. I knew it shouldn't print twice, so I checked the forum, and they were all just running it. Well, now I know that too! 

     I always forget to put a space at the end of the quotes when it is concatenated with anything else. I better get that under control. Creating code with a solid simplicity also needs to be correct, of course. So, I better work on that. Don't want to get a job somewhere and then start doing crap code, do I? Of course not.

Today has been a win for me, I got a lot done, learned a lot of useful stuff, there was only a little bit of stupid. Winning! See y'all Wednesday!

--Martin


Friday, January 17, 2014

Loop Loop Loop... Loop.

     I stayed home today so that I could get some work done around the house. So, no latté or anything for me today. I'll probably do a french press if I find some beans that aren't dead. But I have the music! I didn't really feel the Tomahawk album, so today I'm sticking to some awesome Pink Floyd.
     I've done loops quite a few times and yet, I still can't remember how to do them from memory, so before I do anything in my lessons, I'm going to practice loops until I can remember how to do them from memory. And apparently having:
 for (var i=8; i<120; i+12){
    console.log(i);
}
will freeze the browser. I got it wrong, I know. Now I know not to do <i+12> or anything like that. The correct version:
for (var i=8; i<120; i+=12){
    console.log(i);
}
works. Notice the <i+=12>. Like I said, I need to work on my loops. Onwards and onwards and onwards! Heh. Loop.
Oh look a FizzBuzz. That's got loops. Yay! Good Thing I'm prepared. I like FizzBuzz tests.
     Good Lord the console is so specialized here that even when the code actually works, they just say that it wasn't what they wanted. I should at least be able to see what I did  get to work.
I'm really liking the <for> loops.  It's pretty handy to just have the one line that does so much work.

     So,when you are defining a function, you can use <return> with a string, but otherwise you need <console.log> I guess? OK.
"unreachable 'return' after 'break'." What does that even mean? Here is a part of the code:
var getReview = function (movie) {

switch(movie){
    case "Matrix":
    return "good trip out";
    break;
    case "Princess Bride":
    return "awesome date night movie";
    break;
After each break I got that error,  but the code worked and I passed the lesson. I checked, and that's what they wanted. Why would they want something that has errors to be the answer?
But hey, switch statements.I love their ease and simplicity. Simplicity over all, y'all!  The more I learn, the more I like this language! I'm sure that is true far anyone that likes a computer language. I just feel like I've really hit my stride with my lessons! I've just got to soldier on and get done so I can get a decent job somewhere nice!
I'll see y'all Monday!
--Martin

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