Lottery Number Matching

Here I have tried a bit.

class Constlottery def self.rand_number randoms = loop do puts “Enter a random number” new_number = gets.chomp if new_number.to_s == rand(1…9).to_s puts “You are winner” return else puts “You lost the chance”
end end end end

a = Constlottery.rand_number

puts a

Here I have tried a bit.

class Constlottery def self.rand_number randoms = loop do puts “Enter a random number” new_number = gets.chomp

        if new_number.to_s == rand(1..9).to_s
            puts "You are winner"
            return
        else
            puts "You lost the chance"              
        end

    end
end

end

a = Constlottery.rand_number

puts a

Hi Samir,

Please consider the following

  • this groups isn’t something that you can expect to work on your university assignments
  • we expect you to try and accomplish something by yourself, or search through google, or read some tutorials first before posting here
  • this post is already 3 days old so you should’ve made more progress than what you have right now
  • hearing “I’ve tried a bit” gives the notion that you haven’t tried at all
  • try to analyze what each line of code does and i’m sure you’ll get it
  • get back to this group if you’re really stuck. give us insights on what you’ve done to debug the problem and maybe, there’ll be someone here in the groups to help you Good luck!

Hi Jim. Thanks for the Suggestions. I will definitely work on it…But as i am new to Ruby m a bit worried how to catch the track and jump for development.

Hi Jim. Thanks for the Suggestions. I will definitely work on it…But as i am new to Ruby m a bit worried how to catch the track and jump for development.

Is this something that the university gave you as a personal exercise? Or is this from some site tutorial you’re following. Either way, you should start at the basics of ruby if you’re really new to the language.