Tip:
Highlight text to annotate it
X
Hey guys it's Jake and welcome back to day two of learning to program in Ruby. I hope
you enjoyed the first lesson, and if you haven't already please go ahead and subscribe to the
channel so you don't miss out on any of the next lessons. Okay, Go ahead and open Komodo
Editor or your Editor of choice. Once you have that open go to file and select new ruby.rb.
Today we're going to be going over arithmetic operators. Go into your editor and type in
puts 6 + 11. Go up to file and save as. Type in addition.rb. Go to "start command prompt with ruby from
the start menu and pull in the addition file. And it outputs 17. What it's done is put out 6 + 11 to which
it gives you 17. Okay, This is pretty straight forward with all of the other commands until
we get to the last two. Let's just quickly do the other ones real fast. Come back into
your Komodo editor, and on the next line put puts and let's do 20 -10. Then let's do multiply.
Puts 8 * 10. Puts 100 / 10. These next two are the ones
that are a little tricky. An exponential is just going to be how many times it's multiplied
by itself. To make it easy we will do puts 10 ** 4. Let's save it right there and we'll
go over modulo a little bit later. Just hit save. Go back to your Ruby console and pull
in the file addition. We've told it to puts 6 +11 which is 17. Puts 20 -10 and it puts
10. Puts 8 *10 ten and it returned 80. Then puts 100 / 10 which is 10. Then we told it
to puts 10 ** 4 and it returned 10,000. How we got 10,00 was because we did 10 X 10 X
10 X10 and that's the exponential. So 10 X 10 =100, 100 X 10 = 1000, 10 X 1000 = 10000.
Let's go right back in. We're going to be going over Modulo. Puts 15 % 4. Hit file and
save. Having empty lines is okay. Pull that in. Hit Enter. It's returned 3. So what's
happened here? It says 15 modulo 4. And modulo returns whatever the remainder is in an divided
number. So what it does is take 15 and it divides it by 4. 4 goes into 15 three full
times. But that's not what it's telling us. I probably should've picked a better number.
What it's returning is what's left over. Four can go into fifteen three time and that would
equal twelve. And there's three remaining. That's what it's returning. So let's go back
in here to show you another example. Let's change it to 17 % 4. Hit file save and pull
it back in. You can see here now that it returned a 1 instead of a three. That's because 4 goes
into 17 four full times. Because 4 X 4 = 16 and the remainder is 1. What it's returned
is the remainder number. You might be thinking, "why is this useful?" Actually, it's extremely
useful in any coding. That's why I'm showing you it now. Trust me, you're going to use
it a lot more than you think. Okay, so I hope that was a really good overview of arithmetic
in Ruby. We're going to be going over some more stuff tomorrow. If you haven't already,
please go ahead and subscribe to the channel now. I'm also going to put some links to some
Ruby Coding books on Amazon in the description. You can go down there and look at those. Those
are full breath. You can go over everything. It's what we talked about in the first episode.
So if you want to make a hundred thousand dollars a year than those books are going
to have everything you need. I'm going to put multiple ones down there. Just keep pressing
forward with the videos and we'll talk to you later.