My Journey Of Learning Programming Through Flatiron School #5

My name is Mason Ellwood and I’m currently working on Flatiron School’s Online Full Stack Web Development Program. Each week, I’ll be writing about my experience, what I’m learning, and tips on learning to code.

When going through this school, I want to stress how important it is to take VERY elaborate notes. It has saved me immense time while completing lessons that I have encountered so far. So here is my book unveiled to you for the first time ever: A Comprehensive Guide to Flatiron School’s Online Web Developer Program.

 

My very unspecific title, I know. But while writing my “book”, I have learned how to better teach myself. I have included basically every concept that was new to me and serves as a review of what I know now. And when I say comprehensive I mean….

I currently am on page 60 of my book, and am not sure if it will make it on the “Opera Book of the Month Club”, but it serves its purpose. Enough about that, and let’s get into it! Like I said in the last post, I will be skipping ahead quite a bit, so I can catch up to where I am currently within the school.

 

Puts and Prints

 

Puts or “out*put s*tring” and print are used to display the results you write within the console. Without this and by default ruby will not display any output. It is a way to specifically display data you want to the console. The main difference between these two are puts adds a new line after executing and print does not. Remember you can test this with the IRB workspace.


return value is the data returned to the program by the execution of a method. By default, every method in Ruby returns a value, which is the outputting of the last statement in the method.

As you can see by this, there is the assumption that is should output b, c, and d. But by specifying return will disrupt the execution of your method.

 

Methods and Arguments

When writing your own methods you will encounter arguments that need to be met, so your method will pass. This is created by adding an argument list to the end of your method name by using ().

This allows you to place a user dependent variable within your method, making it dynamic. The above code allows the user to replace x with whatever we want x to equal. X in this example is considered a bare word within the argument list. Allowing us to puts “hello” x amount of times. Once the method has been defined, you now NEED to pass a variable to the bare word when calling the method or else the method will fail and you will receive an argument error.

Which basically says, not all arguments have been met in order for the method to pass. You can also add as many arguments as you would like, by separating them with commas. Arguments create a local variable that can be used within the method when you name an argument, you are then defining what bare words you want to use to access that data

This concept allows you to create dynamic reusable code, remember to work towards the concept of DRY (don’t repeat yourself).

You can also add default arguments to your bare words, try to always use optional or default arguments within your methods. Using the equal sign within your argument list next to each bare word you would like to assign, you can create a default argument making your code more dynamic. But you must place bare words with default values at the end of the argument list. This is considered good practice or your code can return unexpected values.

By default the above method, only outputs the phrase created by the user one time, but can be reused and retold to display phrase as many times as you would like. Remember though, if you set your bare word default to an integer it does not need quotes, if the default is a string it needs to be specified as such with quotes.

 

 

Read More at My Journey Of Learning Programming Through Flatiron School #5

from Web Design Ledger https://webdesignledger.com/my-journey-of-learning-programming-through-flatiron-school-5/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s