Dragon Slayer game in Ruby

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}"
    puts "the dragon killed you"

puts "congrats, you slew the dragon!"

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

I’m just curious, what does rand mean?

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

There is a longer discussion on using rand over here:

thanks m9. I am having fun learning ruby.

1 Like