Doing these exercises is better now, because nothing is new, and more fun, because I'm experimenting as I go along. For instance, the last lesson that I did asked my to simply create and array, called my_array using the numbers 1 through 5. I could have handled it like this:
my_array= [1,2,3,4,5]
...and been done with it. Instead of doing it like that, I went ahead and broke it down like this, right here:
my_array= []
for i in 1..5Yeah...I'm feeling myself. Anyway, I think that this is the best possible route, for me at this point. I tried to do the Ruby tutorial here, but they started talking about having Apache Web Server and, to be honest, I'm not quite ready for all of that, just yet.
my_array<<i
end
I'm trying to make a program that keeps a "to do" list and it's giving me a hard time. A lot of the problem is that because of the way I went through the material in the Book of Ruby, my reading of programs is much better than my writing. Sometimes it's hard for me to remember the exact syntax of what I want to do, so I think going through Code Academy, one more time, will help to cement the way things work in my mind when I'm writing code from scratch.
For instance, I was trying to write a simple program for my if, elsif, and else statement exercise where it gives you messages when you chose any number except "7." This was my program:
print "Enter a number between 1 and 100:"...or something like that. The problem was that Ruby was evaluating "number" as a string and I couldn't figure out how to change that. I used number.to_i!, but that didn't work. The bad news is that I never figured it out; the good news is that now I know about something specific that I need to learn.
number= gets.chomp
if number > 25
puts "Way off!"
elsif number < 25 && !7
puts "Nope, but close"
else
puts "Correct"
end
Once I've finished the Code Academy tutorial, I will start back on the other tutorial that I mentioned previously. I'll be more comfortable with learning about Apache and web servers and other stuff once I'm sure that I have the basic programming stuff done.
No comments:
Post a Comment