December 2014
Beginner
336 pages
7h 41m
English
You have learned if-statements, functions, and arrays. Now it’s time to bend your mind. Type this in, and see if you can figure out what it’s doing.
ex35.rb
1 def gold_room 2 puts "This room is full of gold. How much do you take?" 3 4 print "> " 5 choice = $stdin.gets.chomp 6 7 # this line has a bug, so fix it 8 if choice.include? ("0") || choice.include? ("1") 9 how_much = choice.to_i 10 else 11 dead("Man, learn to type a number.") 12 end 13 14 if how_much < 50 15 puts "Nice, you're not greedy, you win!" 16 exit(0) 17 else 18 dead("You greedy bastard!") 19 end 20 end 21 22 23 ...
Read now
Unlock full access