Wednesday, January 21, 2015

Day 64: Codecademy Javascript Course

I started off the day with this code:

var age = prompt("What's your age?");

if (age < 13){
     console.log("You're allowed to play, but I take no responsibility.");
}

else {
    console.log("Play on!");
}

I programmed this in Javascript and the tutorial congratulated me on writing my first game:

// Check if the user is ready to play!
confirm("I am ready to play!")

var age = prompt("What's your age?");

if (age < 13){
     console.log("You're allowed to play, but I take no responsibility.");
}

else {
    console.log("Play on!");
}

console.log("You are at a Justin Bieber concert, and you hear this lyric 'Lace my shoes off, start racing.'");

console.log("Suddenly, Bieber stops and says, 'Who wants to race me?'")

var userAnswer = prompt("Do you want to race Bieber on stage?")

if (userAnswer === "yes") {
    console.log("You and Bieber start racing. It's neck and neck! You win by a shoelace!");
}

else {
    console.log("Oh no!  Bieber shakes his head and sings 'I set a pace, so I can race without pacing.'");

var feedback = prompt("Rate my game out of 10")

if (feedback > 8) {
    console.log("Thank you! We should race at the next concert!");
}

else {
    console.log("I'll keep practicing coding and racing.");
}

I started working on functions in Javascript today.  This function yields an output of 2:

// This is what a function looks like:

var divideByThree = function (number) {
    var val = number / 3;
    console.log(val);
};

// On line 12, we call the function by name
// Here, it is called 'dividebythree'
// We tell the computer what the number input is (i.e. 6)
// The computer then runs the code inside the function!
divideByThree(6);

When naming functions, the convention is to use CamelCase, an example of which would be "sayHello," in that the first word is not capitalized, but the second word is, and there is no space between the two words (as a bit of trivia, in contrast we have Pascal case, which always begins with a capital letter, like "SayHello").

This is one of the lessons I worked on:

// Below is the greeting function!
// See line 7
// We can join strings together using the plus sign (+)
// See the hint for more details about how this works.

var greeting = function (name) {
    console.log("Great to see you," + " " + name);
};

// On line 11, call the greeting function!

greeting("John")

And the output was:

"Great to see you, John"

These are instructions from Codecademy, which I thought useful to save:

"The var keyword declares a variable named functionName.
The keyword function tells the computer that functionName is a function and not something else.
Parameters go in the parentheses. The computer will look out for it in the code block.
The code block is the reusable code that is between the curly brackets }. Each line of code inside } must end with a semi-colon.
The entire function ends with a semi-colon.
To use the function, we call the function by just typing the function's name, and putting a parameter value inside parentheses after it. The computer will run the reusable code with the specific parameter value substituted into the code."



The instructions go over how functions work.  I entered this function: 
var foodDemand = function(food) {
    console.log("I want to eat" + " " + food);
}; 
Then called it with this:
foodDemand("oranges")
And received this output: 
I want to eat oranges 
We should put a ; at the end of each line of code which is inside of { } and also right after the closing }.  The ; lets the computer know where there are stopping points in the code.  I learned of a programming principle called the D.R.Y. principle, which stands for "Don't Repeat Yourself."  
My next function returned the cost of oranges:
var orangeCost = function (cost) {
    console.log(cost*5);
};
orangeCost(5)
The output is 25.  Then I made my own function, just for practice: 
var howPretty = function (name) {
  console.log(name + " " + "is very pretty");  
};
howPretty("Rachel Phoenix") 
So then, I made this for my girlfriend:


I'm having fun with JavaScript.  :)

SUMMARY OF CODING SKILLS

Total Treehouse Points: 4,236

Treehouse Points by Subject Matter: HTML 663, CSS 1,599, Design 1,193, Development Tools 747, and Miscellaneous
Treehouse Ranking (%): "You have more total points than 88% 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, but switched focus to web dev, as opposed to web design)
Git 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 (37 pg preface and 710 pgs of actual content (as in, I'm not including the book's index))

My Progress on The Odin Project:
1.  Introduction to Web Development             100% Complete
2.  Web Development 101                                29% Complete
3.  Ruby Programming                                       0% Complete
4.  Ruby on Rails                                               0% Complete
5.  HTML5 and CSS3                                           0% Complete
6.  Javascript and JQuery                                  0% Complete
7.  Getting Hired as a Web Developer                 0% Complete

Hours Spent Coding Today: 4
Total Hours Coding: 310

No comments:

Post a Comment