Cover image for Find The Number

Find The Number

thomasbnt profile image Thomas Bnt Updated on ・1 min read

Find The Number

Hello ! The code and the post show my first script in Ruby, please be indulgent.

  • Description

It is a basic 'game' under console/terminal that must be run with ruby.
The goal? Find the exact number.

  • The system

A simple random number for the chances and a condition to check whether it is small or big. If he is too big or too small, he will mark it for you.

Example of the script

  • Code
MaxChiffre = 20
NumberToGuess = Random.new.rand(MaxChiffre)
MaxChance = Random.new.rand(2..6)
a = nil
puts "Enter your number between 0 and #{MaxChiffre} included, you only have #{MaxChance} chances."
for num in 1..MaxChance
  next if a == NumberToGuess
  a = gets.chomp.to_i
  if a > NumberToGuess
    puts "Number too big"
  elsif a < NumberToGuess
    puts "Number too small"
puts "Congratulations, you've found it !" if a == NumberToGuess
puts "Pity ! It was #{NumberToGuess}. " if a != NumberToGuess
  • GitHub

The repository is on GitHub, check out now.

GitHub logo thomasbnt / Find-The-Number

My first script in Ruby.

Posted on by:

thomasbnt profile

Thomas Bnt


French web developer maintly but touches everything, servers, bots, community management, events, social networks and moore. I learn VueJs at this moment and MySQL. β€” Addict to Cappuccino and Music


Editor guide

nice one. however, I would strongly recommend checking the styling guide for Ruby - github.com/rubocop-hq/ruby-style-g.... In the code example, you are using uppercase letters in naming variables - a practice that is foreign in Ruby.


oh yes I know, I had just made the code with capital letters to better find me. 😁


Good use of a GIF to show the gameplay :)


Yeah, it seems easier to show this game πŸ‘Œ


Thank you ! ☺️