Dragon Slayer game in Ruby

ruby

#1

Hey guys, im trying to code the dragon slayer game from javascript in ruby (not exaclty, but the idea)
but when my code is supposed to stop because the dragon killed me, it keeps going. I dont really understand why. All help is greatly appreciated :slight_smile:

dragon = (100)


while dragon > 0 do
    r = rand(10...20)
  if r > 11 
    dragon -= r
    puts r
    puts "Dragon's health is #{dragon}"
  else
    puts "the dragon killed you"
  end
end

puts "congrats, you slew the dragon!"

#2

It's because dragon is still greater than 0, and it loops because of the while loop.


#3

I'm just curious, what does rand mean?


#4

rand(range) means pick a random number from the given range.

There is a longer discussion on using rand over here:


#5

thanks m9. I am having fun learning ruby.