Puts does exactly what you'd think it does: puts whatever comes after it. You can put text or numbers after the puts command, though as of now I remember that text needs to be in parens in Ruby.
Numbers work two days: float (with decimals) and integers (no decimals... like in math class!). Integers work best for now because they are whole numbers. You can do whatever you want with numbers it seems: add, subtract, multiply, divide, for starters.
Not the most original code in the world, but I divided each of the exercises at the end of chapter 2 with puts commands that explain what each number represents. I don't remember yet how to set numbers to strings, so that'll come later.
puts "hours in a year"
puts 24*365
puts "minutes in a decade"
puts 60*24*365*10
puts "my age in seconds"
puts (60*60*365*25)
puts "The answer to 2.4 tough question"
puts 912000000/60/60/24/365
puts 24*365
puts "minutes in a decade"
puts 60*24*365*10
puts "my age in seconds"
puts (60*60*365*25)
puts "The answer to 2.4 tough question"
puts 912000000/60/60/24/365
Nothing really exciting yet. I'll get through another chapter today and try something more original later.
No comments:
Post a Comment